Skip to content

Commit 831a141

Browse files
authored
fix: fall back to conventional commit-parser settings for missing keys (#496)
* fix: fall back to conventional commit-parser settings for missing keys BREAKING CHANGE This potentially changes implicit commitlint behaviour users may have relied on in earlier versions. Instead of falling back to the builtin commit-parser defaults we now default all keys to conventional-changelog-angular. * test: add case for #399 * chore: update yarn.lock * test: sort result lists
1 parent 9ebe8a3 commit 831a141

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

@commitlint/ensure/src/index.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import globby from 'globby';
44
import {camelCase, values} from 'lodash';
55
import * as ensure from '.';
66

7-
test('exports all rules', async t => {
8-
const expected = (await glob('*.js')).map(f => camelCase(f));
9-
const actual = Object.keys(ensure);
7+
test('exports all checkers', async t => {
8+
const expected = (await glob('*.js')).map(f => camelCase(f)).sort();
9+
const actual = Object.keys(ensure).sort();
1010
t.deepEqual(actual, expected);
1111
});
1212

@commitlint/parse/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
},
7474
"dependencies": {
7575
"conventional-changelog-angular": "^1.3.3",
76-
"conventional-commits-parser": "^2.1.0"
76+
"conventional-commits-parser": "^2.1.0",
77+
"lodash": "^4.17.11"
7778
}
7879
}

@commitlint/parse/src/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import {sync} from 'conventional-commits-parser';
22
import defaultChangelogOpts from 'conventional-changelog-angular';
3+
import {merge} from 'lodash';
34

45
export default parse;
56

67
async function parse(message, parser = sync, parserOpts) {
7-
if (!parserOpts || Object.keys(parserOpts || {}).length === 0) {
8-
const changelogOpts = await defaultChangelogOpts;
9-
parserOpts = changelogOpts.parserOpts;
10-
}
11-
12-
const parsed = parser(message, parserOpts);
8+
const defaultOpts = (await defaultChangelogOpts).parserOpts;
9+
const parsed = parser(message, merge({}, defaultOpts, parserOpts));
1310
parsed.raw = message;
1411
return parsed;
1512
}

@commitlint/parse/src/index.test.js

+42
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,45 @@ test('parses custom references', async t => {
164164
repository: null
165165
});
166166
});
167+
168+
test('uses permissive default regex without parser opts', async t => {
169+
const message = 'chore(component,demo): bump';
170+
const actual = await parse(message);
171+
172+
t.is(actual.scope, 'component,demo');
173+
});
174+
175+
test('uses permissive default regex with other parser opts', async t => {
176+
const message = 'chore(component,demo): bump';
177+
const actual = await parse(message, undefined, {commentChar: '#'});
178+
179+
t.is(actual.scope, 'component,demo');
180+
});
181+
182+
test('uses restrictive default regex in passed parser opts', async t => {
183+
const message = 'chore(component,demo): bump';
184+
const actual = await parse(message, undefined, {
185+
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
186+
});
187+
188+
t.is(actual.subject, null);
189+
t.is(actual.scope, null);
190+
});
191+
192+
test('works with chinese scope by default', async t => {
193+
const message = 'fix(面试评价): 测试';
194+
const actual = await parse(message, undefined, {commentChar: '#'});
195+
196+
t.not(actual.subject, null);
197+
t.not(actual.scope, null);
198+
});
199+
200+
test('does not work with chinese scopes with incompatible pattern', async t => {
201+
const message = 'fix(面试评价): 测试';
202+
const actual = await parse(message, undefined, {
203+
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
204+
});
205+
206+
t.is(actual.subject, null);
207+
t.is(actual.scope, null);
208+
});

yarn.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -5704,7 +5704,7 @@ lodash.zip@^4.2.0:
57045704
version "4.2.0"
57055705
resolved "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"
57065706

5707-
[email protected], lodash@^3.3.1, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1:
5707+
[email protected], lodash@^3.3.1, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1:
57085708
version "4.17.11"
57095709
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
57105710
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
@@ -7352,7 +7352,6 @@ resolve-from@^3.0.0:
73527352
resolve-from@^4.0.0:
73537353
version "4.0.0"
73547354
resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
7355-
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
73567355

73577356
resolve-global@^0.1.0:
73587357
version "0.1.0"

0 commit comments

Comments
 (0)