From 25926c6fabfe1e59c34d28fcf6551c4376ed87ce Mon Sep 17 00:00:00 2001 From: Qingyu Wang Date: Sun, 29 Sep 2024 11:34:38 +0800 Subject: [PATCH 1/2] test: using delimiter in `scope-enum` --- @commitlint/rules/src/scope-enum.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/@commitlint/rules/src/scope-enum.test.ts b/@commitlint/rules/src/scope-enum.test.ts index 4b564bf767..184534b608 100644 --- a/@commitlint/rules/src/scope-enum.test.ts +++ b/@commitlint/rules/src/scope-enum.test.ts @@ -11,6 +11,7 @@ const messagesByScope = { multiple: { multiple: 'foo(bar,baz): qux', multipleCommaSpace: 'foo(bar, baz): qux', + multipleSlash: 'foo(bar/baz): qux', }, none: { empty: 'foo: baz', @@ -143,6 +144,16 @@ describe('Scope Enum Validation', () => { expect(message).toEqual('scope must be one of [bar]'); }); }); + + test(`Succeeds with a 'multipleSlash' message when the scopes are included in enum`, async () => { + const [actual, message] = scopeEnum( + await parse(messages['multipleSlash']), + 'always', + ['bar/baz'] + ); + expect(actual).toBeTruthy(); + expect(message).toEqual('scope must be one of [bar/baz]'); + }); }); }); @@ -181,6 +192,16 @@ describe('Scope Enum Validation', () => { expect(message).toEqual('scope must not be one of [bar, baz]'); }); }); + + test(`Fails with a 'multipleSlash' message when the scopes are included in enum`, async () => { + const [actual, message] = scopeEnum( + await parse(messages['multipleSlash']), + 'never', + ['bar/baz'] + ); + expect(actual).toBeFalsy(); + expect(message).toEqual('scope must not be one of [bar/baz]'); + }); }); }); }); From b5893912a688a39c56f3ba0a9dfa9e24dd06e701 Mon Sep 17 00:00:00 2001 From: Qingyu Wang Date: Sun, 29 Sep 2024 11:42:39 +0800 Subject: [PATCH 2/2] feat: support using delimiter in `scope-enum` --- @commitlint/rules/src/scope-enum.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/@commitlint/rules/src/scope-enum.ts b/@commitlint/rules/src/scope-enum.ts index 827f72de63..d7f5957f45 100644 --- a/@commitlint/rules/src/scope-enum.ts +++ b/@commitlint/rules/src/scope-enum.ts @@ -20,10 +20,10 @@ export const scopeEnum: SyncRule = ( let isValid; if (when === 'never') { - isValid = !messageScopes.some(isScopeInEnum); + isValid = !messageScopes.some(isScopeInEnum) && !isScopeInEnum(scope); errorMessage.splice(1, 0, 'not'); } else { - isValid = messageScopes.every(isScopeInEnum); + isValid = messageScopes.every(isScopeInEnum) || isScopeInEnum(scope); } return [isValid, message(errorMessage)];