Skip to content

Commit 5a6a4a8

Browse files
ingmarhmarionebl
authored andcommitted
fix: sentence-case allow upper-case characters in first word (#531)
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: #211
1 parent b2b63e5 commit 5a6a4a8

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
@@ -37,13 +37,8 @@ function toCase(input, target) {
3737
case 'uppercase':
3838
return input.toUpperCase();
3939
case 'sentence-case':
40-
case 'sentencecase': {
41-
const [word] = input.split(' ');
42-
return `${toCase(word.charAt(0), 'upper-case')}${toCase(
43-
word.slice(1),
44-
'lower-case'
45-
)}${input.slice(word.length)}`;
46-
}
40+
case 'sentencecase':
41+
return input.charAt(0).toUpperCase() + input.slice(1);
4742
case 'lower-case':
4843
case 'lowercase':
4944
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)