Skip to content

Commit f04d0db

Browse files
committed
fix: don't merge array properties with custom opts
With a custom "headerCorrespondence" of two entries, commit message subjects couldn't be parsed due to merge with the default (Angular). For example, the following custom parser opts (ESLint style) wouldn't work because "headerCorrespondence" is `['type', 'subject', 'subject']` after the merge. ```js { headerPattern: /^(.*):\s(.*)$/, headerCorrespondence: ['type', 'subject'], } ``` Fixes conventional-changelog#594
1 parent 4ee4544 commit f04d0db

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

@commitlint/parse/src/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import {sync} from 'conventional-commits-parser';
22
import defaultChangelogOpts from 'conventional-changelog-angular';
3-
import {merge} from 'lodash';
3+
import {isArray, mergeWith} from 'lodash';
44

55
export default parse;
66

77
async function parse(message, parser = sync, parserOpts = undefined) {
88
const defaultOpts = (await defaultChangelogOpts).parserOpts;
9-
const parsed = parser(message, merge({}, defaultOpts, parserOpts));
9+
const parsed = parser(
10+
message,
11+
mergeWith({}, defaultOpts, parserOpts, (objValue, srcValue) => {
12+
if (isArray(objValue)) return srcValue;
13+
})
14+
);
1015
parsed.raw = message;
1116
return parsed;
1217
}

@commitlint/parse/src/index.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ test('uses custom opts parser', async t => {
9898
t.deepEqual(actual, expected);
9999
});
100100

101+
test('does not merge array properties with custom opts', async t => {
102+
const message = 'type: subject';
103+
const actual = await parse(message, undefined, {
104+
headerPattern: /^(.*):\s(.*)$/,
105+
headerCorrespondence: ['type', 'subject']
106+
});
107+
const expected = {
108+
body: null,
109+
footer: null,
110+
header: 'type: subject',
111+
mentions: [],
112+
merge: null,
113+
notes: [],
114+
raw: 'type: subject',
115+
references: [],
116+
revert: null,
117+
subject: 'subject',
118+
type: 'type'
119+
};
120+
t.deepEqual(actual, expected);
121+
});
122+
101123
test('supports scopes with /', async t => {
102124
const message = 'type(some/scope): subject';
103125
const actual = await parse(message);

0 commit comments

Comments
 (0)