Skip to content

Commit

Permalink
fix: sentence-case doesn't allow upper-case characters in first word
Browse files Browse the repository at this point in the history
This changes the `sentence-case` rule to also accept upper-case
characters in the first word, allowing the use of acronyms (e.g. "HTML",
"JSX") and words which include upper-case characters (e.g. "JavaScript")
at the beginning of a `sentence-case` input.

For example, with `'subject-case': [2, 'always', 'sentence-case']`, the
following commit messages were rejected (ESLint commit message style):

- `Fix: VAT note not properly displayed`
- `Upgrade: ESLint dev dependency`

Related: conventional-changelog#211
  • Loading branch information
ingmarh committed Dec 29, 2018
1 parent f1d443b commit 3cba1e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions @commitlint/ensure/src/case.js
Expand Up @@ -34,11 +34,8 @@ function toCase(input, target) {
return input.toUpperCase();
case 'sentence-case':
case 'sentencecase': {
const [word] = input.split(' ');
return `${toCase(word.charAt(0), 'upper-case')}${toCase(
word.slice(1),
'lower-case'
)}${input.slice(word.length)}`;
const [firstWord] = input.split(' ');
return firstWord.charAt(0).toUpperCase() + input.slice(1);
}
case 'lower-case':
case 'lowercase':
Expand Down
8 changes: 4 additions & 4 deletions @commitlint/ensure/src/case.test.js
Expand Up @@ -61,16 +61,16 @@ test('false for lowercase on sentencecase', t => {
t.is(ensure('sentence case', 'sentence-case'), false);
});

test('false for UPPERCASE on sentencecase', t => {
t.is(ensure('UPPERCASE', 'sentence-case'), false);
test('true for UPPERCASE on sentencecase', t => {
t.is(ensure('UPPERCASE', 'sentence-case'), true);
});

test('true for Start Case on sentencecase', t => {
t.is(ensure('Start Case', 'sentence-case'), true);
});

test('false for PascalCase on sentencecase', t => {
t.is(ensure('PascalCase', 'sentence-case'), false);
test('true for PascalCase on sentencecase', t => {
t.is(ensure('PascalCase', 'sentence-case'), true);
});

test('false for kebab-case on sentencecase', t => {
Expand Down

0 comments on commit 3cba1e9

Please sign in to comment.