Skip to content

Commit f55521d

Browse files
authored
feat: support using delimiter in scope-enum (#4161)
* test: using delimiter in `scope-enum` * feat: support using delimiter in `scope-enum`
1 parent 729bfb6 commit f55521d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

@commitlint/rules/src/scope-enum.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const messagesByScope = {
1111
multiple: {
1212
multiple: 'foo(bar,baz): qux',
1313
multipleCommaSpace: 'foo(bar, baz): qux',
14+
multipleSlash: 'foo(bar/baz): qux',
1415
},
1516
none: {
1617
empty: 'foo: baz',
@@ -143,6 +144,16 @@ describe('Scope Enum Validation', () => {
143144
expect(message).toEqual('scope must be one of [bar]');
144145
});
145146
});
147+
148+
test(`Succeeds with a 'multipleSlash' message when the scopes are included in enum`, async () => {
149+
const [actual, message] = scopeEnum(
150+
await parse(messages['multipleSlash']),
151+
'always',
152+
['bar/baz']
153+
);
154+
expect(actual).toBeTruthy();
155+
expect(message).toEqual('scope must be one of [bar/baz]');
156+
});
146157
});
147158
});
148159

@@ -181,6 +192,16 @@ describe('Scope Enum Validation', () => {
181192
expect(message).toEqual('scope must not be one of [bar, baz]');
182193
});
183194
});
195+
196+
test(`Fails with a 'multipleSlash' message when the scopes are included in enum`, async () => {
197+
const [actual, message] = scopeEnum(
198+
await parse(messages['multipleSlash']),
199+
'never',
200+
['bar/baz']
201+
);
202+
expect(actual).toBeFalsy();
203+
expect(message).toEqual('scope must not be one of [bar/baz]');
204+
});
184205
});
185206
});
186207
});

@commitlint/rules/src/scope-enum.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export const scopeEnum: SyncRule<string[]> = (
2020
let isValid;
2121

2222
if (when === 'never') {
23-
isValid = !messageScopes.some(isScopeInEnum);
23+
isValid = !messageScopes.some(isScopeInEnum) && !isScopeInEnum(scope);
2424
errorMessage.splice(1, 0, 'not');
2525
} else {
26-
isValid = messageScopes.every(isScopeInEnum);
26+
isValid = messageScopes.every(isScopeInEnum) || isScopeInEnum(scope);
2727
}
2828

2929
return [isValid, message(errorMessage)];

0 commit comments

Comments
 (0)