Skip to content

Commit 7509dc5

Browse files
committed
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.
1 parent 3b3667a commit 7509dc5

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

@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

+25
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,28 @@ 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.message, undefined);
190+
t.is(actual.scope, null);
191+
});

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -5995,7 +5995,7 @@ lodash.zip@^4.2.0:
59955995
version "4.2.0"
59965996
resolved "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"
59975997

5998-
[email protected], lodash@^4.0.0, lodash@^4.17.10:
5998+
[email protected], lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11:
59995999
version "4.17.11"
60006000
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
60016001
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

0 commit comments

Comments
 (0)