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
#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
  • Loading branch information
marionebl authored Nov 30, 2018
1 parent 9ebe8a3 commit 831a141
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
6 changes: 3 additions & 3 deletions @commitlint/ensure/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import globby from 'globby';
import {camelCase, values} from 'lodash';
import * as ensure from '.';

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

Expand Down
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;
}
42 changes: 42 additions & 0 deletions @commitlint/parse/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,45 @@ 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.scope, null);
});

test('works with chinese scope by default', async t => {
const message = 'fix(面试评价): 测试';
const actual = await parse(message, undefined, {commentChar: '#'});

t.not(actual.subject, null);
t.not(actual.scope, null);
});

test('does not work with chinese scopes with incompatible pattern', async t => {
const message = 'fix(面试评价): 测试';
const actual = await parse(message, undefined, {
headerPattern: /^(\w*)(?:\(([a-z]*)\))?: (.*)$/
});

t.is(actual.subject, null);
t.is(actual.scope, null);
});
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5704,7 +5704,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@^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:
[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:
version "4.17.11"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
Expand Down Expand Up @@ -7352,7 +7352,6 @@ resolve-from@^3.0.0:
resolve-from@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==

resolve-global@^0.1.0:
version "0.1.0"
Expand Down

0 comments on commit 831a141

Please sign in to comment.