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]'); + }); }); }); }); 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)];