Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e216d8a

Browse files
committedDec 29, 2018
fix: sentence-case doesn't allow upper-case characters in first word
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
1 parent f1d443b commit e216d8a

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed
 

‎@commitlint/ensure/src/case.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ function toCase(input, target) {
3333
case 'uppercase':
3434
return input.toUpperCase();
3535
case 'sentence-case':
36-
case 'sentencecase': {
37-
const [word] = input.split(' ');
38-
return `${toCase(word.charAt(0), 'upper-case')}${toCase(
39-
word.slice(1),
40-
'lower-case'
41-
)}${input.slice(word.length)}`;
42-
}
36+
case 'sentencecase':
37+
return input.charAt(0).toUpperCase() + input.slice(1);
4338
case 'lower-case':
4439
case 'lowercase':
4540
case 'lowerCase': // Backwards compat config-angular v4

‎@commitlint/ensure/src/case.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ test('false for lowercase on sentencecase', t => {
6161
t.is(ensure('sentence case', 'sentence-case'), false);
6262
});
6363

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

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.