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 30, 2018
1 parent 9ebe8a3 commit fa7aedb
Show file tree
Hide file tree
Showing 4 changed files with 898 additions and 170 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);
});
Loading

0 comments on commit fa7aedb

Please sign in to comment.