Skip to content

Commit 13c4bfc

Browse files
authored
feat: [scope-enum] [scope-case] allow space after comma as scope delimiter (#3577)
fixes #3576
1 parent 85b2808 commit 13c4bfc

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const scopeCase: SyncRule<TargetCaseType | TargetCaseType[]> = (
2727

2828
// Scopes may contain slash or comma delimiters to separate them and mark them as individual segments.
2929
// This means that each of these segments should be tested separately with `ensure`.
30-
const delimiters = /\/|\\|,/g;
30+
const delimiters = /\/|\\|, ?/g;
3131
const scopeSegments = scope.split(delimiters);
3232

3333
const result = checks.some((check) => {

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ const messages = {
66
superfluous: 'foo(): baz',
77
empty: 'foo: baz',
88
multiple: 'foo(bar,baz): qux',
9+
multipleCommaSpace: 'foo(bar, baz): qux',
910
};
1011

1112
const parsed = {
1213
plain: parse(messages.plain),
1314
superfluous: parse(messages.superfluous),
1415
empty: parse(messages.empty),
1516
multiple: parse(messages.multiple),
17+
multipleCommaSpace: parse(messages.multipleCommaSpace),
1618
};
1719

1820
test('scope-enum with plain message and always should succeed empty enum', async () => {
@@ -93,20 +95,29 @@ test('scope-enum with empty scope and never should succeed empty enum', async ()
9395
expect(actual).toEqual(expected);
9496
});
9597

96-
test('scope-enum with multiple scope should succeed on message with multiple scope', async () => {
98+
test('scope-enum with multiple scopes should succeed on message with multiple scopes', async () => {
9799
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'baz']);
98100
const expected = false;
99101
expect(actual).toEqual(expected);
100102
});
101103

102-
test('scope-enum with multiple scope should error on message with forbidden enum', async () => {
104+
test('scope-enum with multiple scopes should error on message with forbidden enum', async () => {
103105
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'qux']);
104106
const expected = true;
105107
expect(actual).toEqual(expected);
106108
});
107109

108-
test('scope-enum with multiple scope should error on message with superfluous scope', async () => {
110+
test('scope-enum with multiple scopes should error on message with superfluous scope', async () => {
109111
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar']);
110112
const expected = true;
111113
expect(actual).toEqual(expected);
112114
});
115+
116+
test('scope-enum with multiple scope with comma+space should succeed on message with multiple scopes', async () => {
117+
const [actual] = scopeEnum(await parsed.multipleCommaSpace, 'always', [
118+
'bar',
119+
'baz',
120+
]);
121+
const expected = true;
122+
expect(actual).toEqual(expected);
123+
});

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const scopeEnum: SyncRule<string[]> = (
1313

1414
// Scopes may contain slash or comma delimiters to separate them and mark them as individual segments.
1515
// This means that each of these segments should be tested separately with `ensure`.
16-
const delimiters = /\/|\\|,/g;
16+
const delimiters = /\/|\\|, ?/g;
1717
const scopeSegments = parsed.scope.split(delimiters);
1818

1919
const negated = when === 'never';

0 commit comments

Comments
 (0)