- Notifications
You must be signed in to change notification settings - Fork 948
Description
Although defined in my commitlint.config.js file as '$', parserOpts.commentChar is superseded by '#'
In the commit messages of my repository, references to issues starts with a '#' character.
I have also set the commentChar for git to '$' since older (before I setup commitlint) commit messages could start with a '#' for such references : git config --local core.commentChar '$'
E.g. of old commit : #123456 - double API now really doubles the passed number
// commitlint.config.js
const ERROR = 2; const WARNING = 1; module.exports = { extends: ['@commitlint/config-conventional'], parserPreset: { parserOpts: { referenceActions: null, commentChar: '$' // <------ SEE HERE } }, rules: { 'body-max-line-length': [ERROR, 'always', 130], 'footer-max-line-length': [ERROR, 'always', 130], 'header-max-length': [ERROR, 'always', 130], 'references-empty': [ERROR, 'never'], 'subject-case': [ERROR, 'never', ['start-case', 'pascal-case', 'upper-case']], 'subject-full-stop': [WARNING, 'never', '.'], 'type-enum': [ERROR, 'always', ['build', 'chore', 'deploy', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'test']] } };// package.json :
"husky": { "hooks": { "pre-commit": "lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS --help-url='https://some.url'" } }, Now with such a config (see my commmitlint.config.js below in details section), I run the following git commit -am "..." commands :
git commit -am "fix: #233601"git commit -am "foo #123456"git commit -athen in the editor opened for the message, I write a single line#123456git commit -am "#123456"
Expected Behavior
- should succeed
- should fail because no type is provided
- should fail because no type is provided
- should fail because no type is provided
Current Behavior
- does succeed ✅
- does fail ✅
- does fail ✅
- does succeed ❌
Affected packages
- cli (I guess)
Possible Solution / Observations
We can observe that :
- commitlint corrrectly discard the message "#123456" when
git commitcommand is used (I guess because it wrongly thinks the message is empty) - commitlint somehow wrongly accepts the same message when
git commit -m "#123456"command is used, despite there are no more lines after wrongly stripping the comments => first bug ?
Also : The logic behind how flags.edit is set to '.git/COMMIT_EDITMSG' from my commitlint -E HUSKY_GIT_PARAMS command in husky pre-commit hook is not clear for me, but for sure this line is very suspicious to me :
commitlint/@commitlint/cli/src/cli.ts
Line 177 in 59667b3
| opts.parserOpts.commentChar = '#'; |
How can commitlint CLI hardcode the comment char as # ?? This does not work for anyone using a different Git commentChar... Somehow commitlint HAS to take into account my commentChar option set in my commitlint.config.js (another option would be to get it from git config, but I guess that's not the purpose of commitlint)
This logic has been introduced by this commit FYI :
35d0ca5
Environment
Reproduced on MacOs and Windows machines.
| Executable | Version |
|---|---|
commitlint --version | @commitlint/cli@11.0.0 |
git --version | git version 2.20.1 (Apple Git-117) |
node --version | v14.8.0 |