Skip to content

feat(core): add sentence-case to ensure-case #117

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

Merged
merged 3 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions @commitlint/core/src/library/ensure-case.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {camelCase, kebabCase, snakeCase, upperFirst, startCase} from 'lodash';

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

export default (raw = '', target = 'lowercase') => {
const input = String(raw);

Expand All @@ -17,6 +21,9 @@ export default (raw = '', target = 'lowercase') => {
case 'upper-case':
case 'uppercase':
return input.toUpperCase() === input;
case 'sentence-case':
case 'sentencecase':
return capitalizeFirstLetter(input.toLowerCase()) === input;
case 'lower-case':
case 'lowercase':
default:
Expand Down
16 changes: 16 additions & 0 deletions @commitlint/core/src/library/ensure-case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ test('false for lowercase on lowercase', t => {
const actual = ensure('a', 'uppercase');
t.is(actual, false);
});

test('true for sentencecase on sentencecase', t => {
const actual = ensure('Sentence case', 'sentencecase');
t.is(actual, true);
});

test('false for sentencecase on sentencecase', t => {
const testCase = 'sentencecase';
t.is(ensure('sentence case', testCase), false);
t.is(ensure('SENTENCE CASE', testCase), false);
t.is(ensure('Sentence Case', testCase), false);
t.is(ensure('sentence-case', testCase), false);
t.is(ensure('SentenceCase', testCase), false);
t.is(ensure('sentence_case', testCase), false);
t.is(ensure('sentenceCase', testCase), false);
});
12 changes: 9 additions & 3 deletions docs/reference-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ Rule configurations are either of type `array` residing on a key with the rule's
'camel-case', // camelCase
'kebab-case', // kebab-case
'pascal-case', // PascalCase
'sentence-case', // Sentence case
'snake-case', // snake_case
'start-case' // Start Case
'start-case', // Start Case
'sentence-case' // Sentence case
]
```

Expand Down Expand Up @@ -155,8 +157,10 @@ Rule configurations are either of type `array` residing on a key with the rule's
'camel-case', // camelCase
'kebab-case', // kebab-case
'pascal-case', // PascalCase
'sentence-case', // Sentence case
Copy link
Contributor Author

@Rugal Rugal Nov 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marionebl This duplicates the docs I added, please see 3 lines below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, deduped it

'snake-case', // snake_case
'start-case' // Start Case
'start-case', // Start Case
'sentence-case' // Sentence case
]
```

Expand Down Expand Up @@ -220,8 +224,10 @@ Rule configurations are either of type `array` residing on a key with the rule's
'camel-case', // camelCase
'kebab-case', // kebab-case
'pascal-case', // PascalCase
'sentence-case', // Sentence case
'snake-case', // snake_case
'start-case' // Start Case
'start-case', // Start Case
'sentence-case' // Sentence case
]
```

Expand Down
34 changes: 4 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ debug@^3.0.1, debug@^3.1.0:
dependencies:
ms "2.0.0"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"

Expand Down Expand Up @@ -3599,7 +3599,7 @@ import-modules@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/import-modules/-/import-modules-1.1.0.tgz#748db79c5cc42bb9701efab424f894e72600e9dc"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

Expand Down Expand Up @@ -4460,39 +4460,17 @@ lockfile@~1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/lockfile/-/lockfile-1.0.3.tgz#2638fc39a0331e9cac1a04b71799931c9c50df79"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.npmjs.org/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.npmjs.org/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
dependencies:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.npmjs.org/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.npmjs.org/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.npmjs.org/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"

lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -4549,10 +4527,6 @@ lodash.merge@^4.6.0:
version "4.6.0"
resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.0.tgz#69884ba144ac33fe699737a6086deffadd0f89c5"

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

lodash.snakecase@^4.0.1:
version "4.1.1"
resolved "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
Expand Down Expand Up @@ -5865,7 +5839,7 @@ readable-stream@~1.1.10:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
dependencies:
Expand Down Expand Up @@ -7028,7 +7002,7 @@ v8flags@^2.1.1:
dependencies:
user-home "^1.1.1"

validate-npm-package-license@*, validate-npm-package-license@^3.0.1:
validate-npm-package-license@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
dependencies:
Expand Down