Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 4 tasks
Joxtacy opened this issue Jul 11, 2024 · 8 comments
Open
1 of 4 tasks

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

Joxtacy opened this issue Jul 11, 2024 · 8 comments

Comments

@Joxtacy
Copy link

Joxtacy commented Jul 11, 2024

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

  • 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

@Joxtacy Joxtacy added the bug label Jul 11, 2024
@Joxtacy
Copy link
Author

Joxtacy commented Jul 11, 2024

@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
Copy link
Member

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

@yagnikvadi2003
Copy link

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

@ext
Copy link

ext commented Sep 13, 2024

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)

@escapedcat
Copy link
Member

@ext I tried to update relevant packages here but got stuck: #4069
Happy for any help!

@skycaptain
Copy link
Contributor

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

@magneland
Copy link

magneland commented Oct 2, 2024

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

@mheob
Copy link

mheob commented Oct 15, 2024

Just as an extended note:
The issue also occurs when I use external tools, such as CZ-Git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants