Skip to content

Commit

Permalink
feat: [scope-enum] [scope-case] allow space after comma as scope deli…
Browse files Browse the repository at this point in the history
…miter (#3577)

fixes #3576
  • Loading branch information
miluoshi committed Oct 25, 2023
1 parent 85b2808 commit 13c4bfc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion @commitlint/rules/src/scope-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const scopeCase: SyncRule<TargetCaseType | TargetCaseType[]> = (

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

const result = checks.some((check) => {
Expand Down
17 changes: 14 additions & 3 deletions @commitlint/rules/src/scope-enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const messages = {
superfluous: 'foo(): baz',
empty: 'foo: baz',
multiple: 'foo(bar,baz): qux',
multipleCommaSpace: 'foo(bar, baz): qux',
};

const parsed = {
plain: parse(messages.plain),
superfluous: parse(messages.superfluous),
empty: parse(messages.empty),
multiple: parse(messages.multiple),
multipleCommaSpace: parse(messages.multipleCommaSpace),
};

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

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

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

test('scope-enum with multiple scope should error on message with superfluous scope', async () => {
test('scope-enum with multiple scopes should error on message with superfluous scope', async () => {
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar']);
const expected = true;
expect(actual).toEqual(expected);
});

test('scope-enum with multiple scope with comma+space should succeed on message with multiple scopes', async () => {
const [actual] = scopeEnum(await parsed.multipleCommaSpace, 'always', [
'bar',
'baz',
]);
const expected = true;
expect(actual).toEqual(expected);
});
2 changes: 1 addition & 1 deletion @commitlint/rules/src/scope-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const scopeEnum: SyncRule<string[]> = (

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

const negated = when === 'never';
Expand Down

0 comments on commit 13c4bfc

Please sign in to comment.