conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.56k stars 888 forks source link

fix: `!` gives errors when using `parserPreset` in config #4100

Open Joxtacy opened 1 month ago

Joxtacy commented 1 month ago

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

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/cli@19.3.0

git --version

v2.45.2

node --version

v20.15.0

Joxtacy commented 1 month ago

@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.

escapedcat commented 1 month ago

👏 Thanks for your feedback!
If you want to you could give debugging a try. We're happy for any help.

yagnikvadi2003 commented 2 weeks ago

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