Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/numeric subject case #451

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions @commitlint/ensure/src/case.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ensureCase(raw = '', target = 'lowercase') {
.trim();
const transformed = toCase(input, target);

if (transformed === '') {
if (transformed === '' || transformed.match(/^\d/)) {
return true;
}

Expand All @@ -38,7 +38,7 @@ function toCase(input, target) {
return input.toUpperCase();
case 'sentence-case':
case 'sentencecase': {
const word = input.split(' ')[0];
const [word] = input.split(' ');
return `${toCase(word.charAt(0), 'upper-case')}${toCase(
word.slice(1),
'lower-case'
Expand Down
28 changes: 28 additions & 0 deletions @commitlint/ensure/src/case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,31 @@ test('false for `LOWERCASE on lowercase', t => {
const actual = ensure('`LOWERCASE', 'lowercase');
t.is(actual, false);
});

test('true for numeric on camel-case', t => {
t.true(ensure('1.0.0', 'camel-case'));
});

test('true for numeric on kebab-case', t => {
t.true(ensure('1.0.0', 'kebab-case'));
});

test('true for numeric on snake-case', t => {
t.true(ensure('1.0.0', 'snake-case'));
});

test('true for numeric on pascal-case', t => {
t.true(ensure('1.0.0', 'pascal-case'));
});

test('true for numeric on uppercase', t => {
t.true(ensure('1.0.0', 'uppercase'));
});

test('true for numeric on sentencecase', t => {
t.true(ensure('1.0.0', 'sentencecase'));
});

test('true for numeric on lowercase', t => {
t.true(ensure('1.0.0', 'lowercase'));
});
2 changes: 1 addition & 1 deletion @commitlint/rules/src/subject-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const negated = when => when === 'never';
export default (parsed, when, value) => {
const {subject} = parsed;

if (typeof subject !== 'string') {
if (typeof subject !== 'string' || !subject.match(/^[a-z]/i)) {
return [true];
}

Expand Down
26 changes: 26 additions & 0 deletions @commitlint/rules/src/subject-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import subjectCase from './subject-case';

const messages = {
empty: 'test:\n',
numeric: 'test: 1.0.0',
lowercase: 'test: subject',
mixedcase: 'test: sUbJeCt',
uppercase: 'test: SUBJECT',
Expand All @@ -16,6 +17,7 @@ const messages = {

const parsed = {
empty: parse(messages.empty),
numeric: parse(messages.numeric),
lowercase: parse(messages.lowercase),
mixedcase: parse(messages.mixedcase),
uppercase: parse(messages.uppercase),
Expand Down Expand Up @@ -324,3 +326,27 @@ test('with uppercase scope should fail for "never [uppercase, lowercase]"', asyn
const expected = false;
t.is(actual, expected);
});

test('with numeric subject should succeed for "never lowercase"', async t => {
const [actual] = subjectCase(await parsed.numeric, 'never', 'lowercase');
const expected = true;
t.is(actual, expected);
});

test('with numeric subject should succeed for "always lowercase"', async t => {
const [actual] = subjectCase(await parsed.numeric, 'always', 'lowercase');
const expected = true;
t.is(actual, expected);
});

test('with numeric subject should succeed for "never uppercase"', async t => {
const [actual] = subjectCase(await parsed.numeric, 'never', 'uppercase');
const expected = true;
t.is(actual, expected);
});

test('with numeric subject should succeed for "always uppercase"', async t => {
const [actual] = subjectCase(await parsed.numeric, 'always', 'uppercase');
const expected = true;
t.is(actual, expected);
});