conventional-changelog/commitlint

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

Chiusa

#4100 aperta il 11 lug 2024

 (11 commenti) (3 reazioni) (0 assegnatari)TypeScript (896 fork)batch import
bughelp wanted

Metriche repository

Star
 (15.497 stelle)
Metriche merge PR
 (Merge medio 12h 56m) (52 PR mergiate in 30 g)

Descrizione

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

git --version

v2.45.2

node --version

v20.15.0

Guida contributor