Skip to content

Commit 73632ce

Browse files
authoredJun 21, 2020
feat: enable multiple scopes in scope-enum and scope-case rules (#901)
1 parent 94f0b53 commit 73632ce

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed
 

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export const scopeCase: SyncRule<TargetCaseType | TargetCaseType[]> = (
2525
return check;
2626
});
2727

28-
// Scopes may contain slash-delimiters to separate them and mark them as individual segments.
28+
// 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

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {scopeEnum} from './scope-enum';
44
const messages = {
55
plain: 'foo(bar): baz',
66
superfluous: 'foo(): baz',
7-
empty: 'foo: baz'
7+
empty: 'foo: baz',
8+
multiple: 'foo(bar,baz): qux'
89
};
910

1011
const parsed = {
1112
plain: parse(messages.plain),
1213
superfluous: parse(messages.superfluous),
13-
empty: parse(messages.empty)
14+
empty: parse(messages.empty),
15+
multiple: parse(messages.multiple)
1416
};
1517

1618
test('scope-enum with plain message and always should succeed empty enum', async () => {
@@ -90,3 +92,21 @@ test('scope-enum with empty scope and never should succeed empty enum', async ()
9092
const expected = true;
9193
expect(actual).toEqual(expected);
9294
});
95+
96+
test('scope-enum with multiple scope should succeed on message with multiple scope', async () => {
97+
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'baz']);
98+
const expected = false;
99+
expect(actual).toEqual(expected);
100+
});
101+
102+
test('scope-enum with multiple scope should error on message with forbidden enum', async () => {
103+
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar', 'qux']);
104+
const expected = true;
105+
expect(actual).toEqual(expected);
106+
});
107+
108+
test('scope-enum with multiple scope should error on message with superfluous scope', async () => {
109+
const [actual] = scopeEnum(await parsed.multiple, 'never', ['bar']);
110+
const expected = true;
111+
expect(actual).toEqual(expected);
112+
});

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ export const scopeEnum: SyncRule<string[]> = (
1111
return [true, ''];
1212
}
1313

14+
// Scopes may contain slash or comma delimiters to separate them and mark them as individual segments.
15+
// This means that each of these segments should be tested separately with `ensure`.
16+
const delimiters = /\/|\\|,/g;
17+
const scopeSegments = parsed.scope.split(delimiters);
18+
1419
const negated = when === 'never';
15-
const result = value.length === 0 || ensure.enum(parsed.scope, value);
20+
const result =
21+
value.length === 0 ||
22+
scopeSegments.every(scope => ensure.enum(scope, value));
1623

1724
return [
1825
negated ? !result : result,

0 commit comments

Comments
 (0)
Please sign in to comment.