fix: `!` gives errors when using `parserPreset` in config
Steps to Reproduce
I have prepared a branch in my repo [here (branch commitlint-error-testing)](https://github.com/Joxtacy/automatic-release-notes-testing/tree/commitlint-error-testing) which has the broken config.
1. Have a config file with `parserPreset` config.
import type {UserConfig} from '@commitlint/types';
import {RuleConfigSeverity} from '@commitlint/types';
const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
parserPreset: 'conventional-changelog-atom',
formatter: '@commitlint/format',
rules: {
'type-enum': [RuleConfigSeverity.Error, 'always', ['foo']],
},
// ...
};
export default Configuration;
2. Create a commit with a commit message similar to `feat!: subject`
Current Behavior
When the linter runs with a commit message containing ! the linter spits out the following error
❯ git commit -m 'feat!: subject'
╭──────────────────────────────────────╮
│ 🥊 lefthook v1.7.2 hook: commit-msg │
╰──────────────────────────────────────╯
┃ lint commit message ❯
⧗ input: feat!: subject
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
⚠ scope may not be empty [scope-empty]
✖ found 2 problems, 1 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
────────────────────────────────────
summary: (done in 0.70 seconds)
🥊 lint commit message
Expected Behavior
I expect the linter to pass with a message containing !, like feat!: subject.
Affected packages
- [X] cli
- [ ] core
- [ ] prompt
- [ ] config-angular
Possible Solution
Haven't looked into the codebase, so can't give a possible solution to this right now.
Context
I'm just trying to run the linter on a commit hook, and to have the ! be correctly parsed. 🙃
commitlint --version
@commitlint/[email protected]
git --version
v2.45.2
node --version
v20.15.0
@escapedcat
Hi! It's me again, from #3492
I did some more testing with the configs and I could conclude that it was the parserPreset in my config that caused the issues. When I removed it, the ! was parsed as expected.
Edit: Let me know if I can be of any more help. I'd love to help out if I can.
👏 Thanks for your feedback!
If you want to you could give debugging a try. We're happy for any help.
the same problem, i think this problem is commitlint library side, because I already tried and follow every commitlint rule but not solve this problem
I'm having this issue as well. I wonder if it would be resolved by #4064 as conventional-commits-parser includes this in the release notes:
conventional-commits-parser: parse header if subject includes ! to indicate breaking change (conventional-changelog/conventional-changelog#1213)
@ext I tried to update relevant packages here but got stuck: #4069
Happy for any help!
Having the same issue. I think its not related to parserPreset, as even a very simple example fails, e.g. taking the example from https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with--to-draw-attention-to-breaking-change:
$ echo "feat!: send an email to the customer when a product is shipped" | npx @commitlint/cli -x @commitlint/config-conventional
⧗ input: feat!: send an email to the customer when a product is shipped
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
I just wanted to mention that the use of single quotes versus double quotes matter in bash, zsh, etc. Basically ! is the history expansion modifier and needs to be escaped sometimes. Things to verify locally:
echo !
echo \!
echo '!'
echo "\!"
echo "!" # probably will choke
Just as an extended note: The issue also occurs when I use external tools, such as CZ-Git.
Same issue, can someone fix it? See PR in review
Sorry for bumping a rather old thread, but why exactly isn't there any progress on this? From what I can see all of the following are either related or link to each other:
- https://github.com/conventional-changelog/commitlint/issues/4191
- https://github.com/conventional-changelog/commitlint/pull/4063
- https://github.com/conventional-changelog/commitlint/pull/4069#issuecomment-2160348473
It appears multiple people have come up with a solution of some sort for this problem, most of these involve changing things in package.json. Why is none of these solutions "upstreamed" or implemented here?
I agree this may be a viable fix for JS projects, but I'm trying to use commitlint via the container image provided on docker.io for both CI on GitLab as well as locally via CLI. If the "fix" for this entails patching foreign dependencies that essentially means I'll have to maintain my own version of this container which seems like a lot of unnecessary trouble.
I just verified that commit messages with a ! appended to the type fail both on the 19.8.1 container and on master (sha256:02d122554df479743dfec25bec9410e6d39807ca6db4e4c0ea7823a50f997ba2) as well.