diff --git a/@commitlint/ensure/src/case.js b/@commitlint/ensure/src/case.js index 6de9e889b2..fdb51e83b4 100644 --- a/@commitlint/ensure/src/case.js +++ b/@commitlint/ensure/src/case.js @@ -9,13 +9,7 @@ function ensureCase(raw = '', target = 'lowercase') { .replace(/`.*?`|".*?"|'.*?'/g, '') .trim(); - const delimiters = /(\/|\\)/g; - const transformed = input - .split(delimiters) - .map(segment => - delimiters.test(segment) ? segment : toCase(segment, target) - ) - .join(''); + const transformed = toCase(input, target); if (transformed === '' || transformed.match(/^\d/)) { return true; diff --git a/@commitlint/ensure/src/case.test.js b/@commitlint/ensure/src/case.test.js index b3e1cb04a2..f04fccc0d1 100644 --- a/@commitlint/ensure/src/case.test.js +++ b/@commitlint/ensure/src/case.test.js @@ -110,11 +110,6 @@ test('true for * on pascal-case', t => { t.is(actual, true); }); -test('true for Modules/Graph on pascal-case', t => { - const actual = ensure('Modules/Graph', 'pascal-case'); - t.is(actual, true); -}); - test('true for * on start-case', t => { const actual = ensure('*', 'start-case'); t.is(actual, true); diff --git a/@commitlint/rules/src/scope-case.js b/@commitlint/rules/src/scope-case.js index a7fa546474..b74e9a66d2 100644 --- a/@commitlint/rules/src/scope-case.js +++ b/@commitlint/rules/src/scope-case.js @@ -20,8 +20,16 @@ export default (parsed, when, value) => { return check; }); + // Scopes may contain slash-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 scopeSegments = scope.split(delimiters); + const result = checks.some(check => { - const r = ensure.case(scope, check.case); + const r = scopeSegments.every( + segment => delimiters.test(segment) || ensure.case(segment, check.case) + ); + return negated(check.when) ? !r : r; }); diff --git a/@commitlint/rules/src/scope-case.test.js b/@commitlint/rules/src/scope-case.test.js index 8499357c57..e75b9310eb 100644 --- a/@commitlint/rules/src/scope-case.test.js +++ b/@commitlint/rules/src/scope-case.test.js @@ -308,3 +308,17 @@ test('with uppercase scope should fail for "never [uppercase, lowercase]"', asyn const expected = false; t.is(actual, expected); }); + +test('with slash in scope should succeed for "always pascal-case"', async t => { + const commit = await parse('feat(Modules/Graph): add Pie Chart'); + const [actual] = scopeCase(commit, 'always', 'pascal-case'); + const expected = true; + t.is(actual, expected); +}); + +test('with slash in subject should succeed for "always sentence case"', async t => { + const commit = await parse('chore: Update @angular/core'); + const [actual] = scopeCase(commit, 'always', 'sentencecase'); + const expected = true; + t.is(actual, expected); +});