diff --git a/@commitlint/rules/src/scope-case.js b/@commitlint/rules/src/scope-case.js index 1348908939..a7fa546474 100644 --- a/@commitlint/rules/src/scope-case.js +++ b/@commitlint/rules/src/scope-case.js @@ -1,6 +1,8 @@ import * as ensure from '@commitlint/ensure'; import message from '@commitlint/message'; +const negated = when => when === 'never'; + export default (parsed, when, value) => { const {scope} = parsed; @@ -8,11 +10,25 @@ export default (parsed, when, value) => { return [true]; } - const negated = when === 'never'; + const checks = (Array.isArray(value) ? value : [value]).map(check => { + if (typeof check === 'string') { + return { + when: 'always', + case: check + }; + } + return check; + }); + + const result = checks.some(check => { + const r = ensure.case(scope, check.case); + return negated(check.when) ? !r : r; + }); + + const list = checks.map(c => c.case).join(', '); - const result = ensure.case(scope, value); return [ - negated ? !result : result, - message([`scope must`, negated ? `not` : null, `be ${value}`]) + negated(when) ? !result : result, + message([`scope must`, negated(when) ? `not` : null, `be ${list}`]) ]; }; diff --git a/@commitlint/rules/src/scope-case.test.js b/@commitlint/rules/src/scope-case.test.js index cdd548124c..8499357c57 100644 --- a/@commitlint/rules/src/scope-case.test.js +++ b/@commitlint/rules/src/scope-case.test.js @@ -248,8 +248,63 @@ test('with uppercase scope should fail for "never uppercase"', async t => { t.is(actual, expected); }); -test('with lowercase scope should succeed for "always uppercase"', async t => { +test('with uppercase scope should succeed for "always uppercase"', async t => { const [actual] = scopeCase(await parsed.uppercase, 'always', 'uppercase'); const expected = true; t.is(actual, expected); }); + +test('with uppercase scope should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = scopeCase(await parsed.uppercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with lowercase scope should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = scopeCase(await parsed.lowercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase scope should fail for "always [uppercase, lowercase]"', async t => { + const [actual] = scopeCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +}); + +test('with mixedcase scope should pass for "always [uppercase, lowercase, camel-case]"', async t => { + const [actual] = scopeCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase', + 'camel-case' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase scope should pass for "never [uppercase, lowercase]"', async t => { + const [actual] = scopeCase(await parsed.mixedcase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with uppercase scope should fail for "never [uppercase, lowercase]"', async t => { + const [actual] = scopeCase(await parsed.uppercase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +}); diff --git a/@commitlint/rules/src/subject-case.test.js b/@commitlint/rules/src/subject-case.test.js index db66db7236..8add629847 100644 --- a/@commitlint/rules/src/subject-case.test.js +++ b/@commitlint/rules/src/subject-case.test.js @@ -269,3 +269,58 @@ test('should use expected message with "never"', async t => { ); t.true(message.indexOf('must not be upper-case') > -1); }); + +test('with uppercase scope should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = subjectCase(await parsed.uppercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with lowercase subject should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = subjectCase(await parsed.lowercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase subject should fail for "always [uppercase, lowercase]"', async t => { + const [actual] = subjectCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +}); + +test('with mixedcase subject should pass for "always [uppercase, lowercase, camel-case]"', async t => { + const [actual] = subjectCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase', + 'camel-case' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase scope should pass for "never [uppercase, lowercase]"', async t => { + const [actual] = subjectCase(await parsed.mixedcase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with uppercase scope should fail for "never [uppercase, lowercase]"', async t => { + const [actual] = subjectCase(await parsed.uppercase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +}); diff --git a/@commitlint/rules/src/type-case.js b/@commitlint/rules/src/type-case.js index 2a09198e8b..c13144f006 100644 --- a/@commitlint/rules/src/type-case.js +++ b/@commitlint/rules/src/type-case.js @@ -1,6 +1,8 @@ import * as ensure from '@commitlint/ensure'; import message from '@commitlint/message'; +const negated = when => when === 'never'; + export default (parsed, when, value) => { const {type} = parsed; @@ -8,11 +10,25 @@ export default (parsed, when, value) => { return [true]; } - const negated = when === 'never'; + const checks = (Array.isArray(value) ? value : [value]).map(check => { + if (typeof check === 'string') { + return { + when: 'always', + case: check + }; + } + return check; + }); + + const result = checks.some(check => { + const r = ensure.case(type, check.case); + return negated(check.when) ? !r : r; + }); + + const list = checks.map(c => c.case).join(', '); - const result = ensure.case(type, value); return [ - negated ? !result : result, - message([`type must`, negated ? `not` : null, `be ${value}`]) + negated(when) ? !result : result, + message([`type must`, negated(when) ? `not` : null, `be ${list}`]) ]; }; diff --git a/@commitlint/rules/src/type-case.test.js b/@commitlint/rules/src/type-case.test.js index d64da960b9..43f0903a8e 100644 --- a/@commitlint/rules/src/type-case.test.js +++ b/@commitlint/rules/src/type-case.test.js @@ -268,3 +268,58 @@ test('with startcase type should succeed for "always startcase"', async t => { const expected = true; t.is(actual, expected); }); + +test('with uppercase scope should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = typeCase(await parsed.uppercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with lowercase subject should succeed for "always [uppercase, lowercase]"', async t => { + const [actual] = typeCase(await parsed.lowercase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase subject should fail for "always [uppercase, lowercase]"', async t => { + const [actual] = typeCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +}); + +test('with mixedcase subject should pass for "always [uppercase, lowercase, camel-case]"', async t => { + const [actual] = typeCase(await parsed.mixedcase, 'always', [ + 'uppercase', + 'lowercase', + 'camel-case' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with mixedcase scope should pass for "never [uppercase, lowercase]"', async t => { + const [actual] = typeCase(await parsed.mixedcase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = true; + t.is(actual, expected); +}); + +test('with uppercase scope should fail for "never [uppercase, lowercase]"', async t => { + const [actual] = typeCase(await parsed.uppercase, 'never', [ + 'uppercase', + 'lowercase' + ]); + const expected = false; + t.is(actual, expected); +});