Expected Behavior
Custom "parserOpts" key values in commitlint.config.js take precedence over the default "parserOpts" (from conventional-changelog-angular).
E.g. using ['type', 'subject'] for "headerCorrespondence" works.
Current Behavior
When using custom "parserOpts" in commitlint.config.js, array properties are merged with the default. E.g. setting "headerCorrespondence" to ['type', 'subject'] (ESLint convention) becomes ['type', 'subject', 'subject'] after merging the "parserOpts" object with conventional-changelog-angular "parserOpts".
This means that when using the "subject-empty" rule to ensure that the subject is not empty, it would always error ("subject may not be empty") in this case.
Affected packages
Possible Solution
The cause is the "parserOpts" merge introduced with #496 (commitlint 7.5.0): Lodash merge also merges array and plain object properties recursively. So this can probably be addressed in @commitlint/parse/src/index.js.
One solution could be to skip array objects when merging (if there's no need to merge those). For example, using Lodash mergeWith:
_.mergeWith({}, defaultOpts, parserOpts, (objValue, srcValue) => {
if (_.isArray(objValue)) return srcValue
})
Steps to Reproduce (for bugs)
- Use commitlint >= 7.5.0 and set up
commitlint.config.js (see below)
- Try
echo 'Fix: Any subject' | commitlint
- It always fails with
subject may not be empty [subject-empty]
commitlint.config.js
// ESLint Commit Message style
module.exports = {
parserPreset: {
parserOpts: {
headerPattern: /^(.*):\s(.*)$/,
headerCorrespondence: ['type', 'subject'],
},
},
rules: {
'subject-empty': [2, 'never'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always', ['Fix', 'Update', 'New', 'Breaking', 'Docs', 'Build', 'Upgrade', 'Chore']],
},
}
Context
In order to use ESLint Commit Message convention and own "issuePrefixes", we set up custom "parserOpts" in commitlint.config.js.
(As a workaround, we're currently setting "headerCorrespondence" to ['type', 'subject', 'unused'] to avoid the problem.)
Your Environment
| Executable |
Version |
commitlint --version |
7.5.2 |
git --version |
2.18.0 |
node --version |
8.15.0 |
Expected Behavior
Custom "parserOpts" key values in
commitlint.config.jstake precedence over the default "parserOpts" (fromconventional-changelog-angular).E.g. using
['type', 'subject']for "headerCorrespondence" works.Current Behavior
When using custom "parserOpts" in
commitlint.config.js, array properties are merged with the default. E.g. setting "headerCorrespondence" to['type', 'subject'](ESLint convention) becomes['type', 'subject', 'subject']after merging the "parserOpts" object withconventional-changelog-angular"parserOpts".This means that when using the "subject-empty" rule to ensure that the subject is not empty, it would always error ("subject may not be empty") in this case.
Affected packages
Possible Solution
The cause is the "parserOpts" merge introduced with #496 (commitlint 7.5.0): Lodash
mergealso merges array and plain object properties recursively. So this can probably be addressed in@commitlint/parse/src/index.js.One solution could be to skip array objects when merging (if there's no need to merge those). For example, using Lodash
mergeWith:Steps to Reproduce (for bugs)
commitlint.config.js(see below)echo 'Fix: Any subject' | commitlintsubject may not be empty [subject-empty]commitlint.config.js
Context
In order to use ESLint Commit Message convention and own "issuePrefixes", we set up custom "parserOpts" in
commitlint.config.js.(As a workaround, we're currently setting "headerCorrespondence" to
['type', 'subject', 'unused']to avoid the problem.)Your Environment
commitlint --versiongit --versionnode --version