diff --git a/@commitlint/parse/src/index.js b/@commitlint/parse/src/index.js index dfb96f1dcb..ee4f7742ce 100644 --- a/@commitlint/parse/src/index.js +++ b/@commitlint/parse/src/index.js @@ -1,12 +1,17 @@ import {sync} from 'conventional-commits-parser'; import defaultChangelogOpts from 'conventional-changelog-angular'; -import {merge} from 'lodash'; +import {isArray, mergeWith} from 'lodash'; export default parse; async function parse(message, parser = sync, parserOpts = undefined) { const defaultOpts = (await defaultChangelogOpts).parserOpts; - const parsed = parser(message, merge({}, defaultOpts, parserOpts)); + const parsed = parser( + message, + mergeWith({}, defaultOpts, parserOpts, (objValue, srcValue) => { + if (isArray(objValue)) return srcValue; + }) + ); parsed.raw = message; return parsed; } diff --git a/@commitlint/parse/src/index.test.js b/@commitlint/parse/src/index.test.js index 1da6464b7f..f44a1182bb 100644 --- a/@commitlint/parse/src/index.test.js +++ b/@commitlint/parse/src/index.test.js @@ -98,6 +98,28 @@ test('uses custom opts parser', async t => { t.deepEqual(actual, expected); }); +test('does not merge array properties with custom opts', async t => { + const message = 'type: subject'; + const actual = await parse(message, undefined, { + headerPattern: /^(.*):\s(.*)$/, + headerCorrespondence: ['type', 'subject'] + }); + const expected = { + body: null, + footer: null, + header: 'type: subject', + mentions: [], + merge: null, + notes: [], + raw: 'type: subject', + references: [], + revert: null, + subject: 'subject', + type: 'type' + }; + t.deepEqual(actual, expected); +}); + test('supports scopes with /', async t => { const message = 'type(some/scope): subject'; const actual = await parse(message);