Skip to content

Commit

Permalink
fix: fall back to conventional commit-parser settings for missing keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marionebl committed Nov 25, 2018
1 parent 3b3667a commit 7509dc5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion @commitlint/parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
},
"dependencies": {
"conventional-changelog-angular": "^1.3.3",
"conventional-commits-parser": "^2.1.0"
"conventional-commits-parser": "^2.1.0",
"lodash": "^4.17.11"
}
}
9 changes: 3 additions & 6 deletions @commitlint/parse/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {sync} from 'conventional-commits-parser';
import defaultChangelogOpts from 'conventional-changelog-angular';
import {merge} from 'lodash';

export default parse;

async function parse(message, parser = sync, parserOpts) {
if (!parserOpts || Object.keys(parserOpts || {}).length === 0) {
const changelogOpts = await defaultChangelogOpts;
parserOpts = changelogOpts.parserOpts;
}

const parsed = parser(message, parserOpts);
const defaultOpts = (await defaultChangelogOpts).parserOpts;
const parsed = parser(message, merge({}, defaultOpts, parserOpts));
parsed.raw = message;
return parsed;
}
25 changes: 25 additions & 0 deletions @commitlint/parse/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,28 @@ test('parses custom references', async t => {
repository: null
});
});

test('uses permissive default regex without parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message);

t.is(actual.scope, 'component,demo');
});

test('uses permissive default regex with other parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message, undefined, {commentChar: '#'});

t.is(actual.scope, 'component,demo');
});

test('uses restrictive default regex in passed parser opts', async t => {
const message = 'chore(component,demo): bump';
const actual = await parse(message, undefined, {
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
});

t.is(actual.subject, null);
t.is(actual.message, undefined);
t.is(actual.scope, null);
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5995,7 +5995,7 @@ lodash.zip@^4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"

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

0 comments on commit 7509dc5

Please sign in to comment.