Skip to content

feat: [scope-enum] [scope-case] allow space after comma as scope delimiter #3577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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