diff --git a/@commitlint/parse/package.json b/@commitlint/parse/package.json index 4123d88c53..d590314b6b 100644 --- a/@commitlint/parse/package.json +++ b/@commitlint/parse/package.json @@ -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" } } diff --git a/@commitlint/parse/src/index.js b/@commitlint/parse/src/index.js index 0c71d40e2f..363e81a382 100644 --- a/@commitlint/parse/src/index.js +++ b/@commitlint/parse/src/index.js @@ -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; } diff --git a/@commitlint/parse/src/index.test.js b/@commitlint/parse/src/index.test.js index 78d7aa7d73..80b26a542a 100644 --- a/@commitlint/parse/src/index.test.js +++ b/@commitlint/parse/src/index.test.js @@ -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); +}); diff --git a/yarn.lock b/yarn.lock index 83c695a60b..203f3496b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" -lodash@4.17.11, lodash@^4.0.0, lodash@^4.17.10: +lodash@4.17.11, 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==