conventional-changelog/commitlint

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

Closed

#4,100 opened on Jul 11, 2024

 (11 comments) (3 reactions) (0 assignees)TypeScript (896 forks)batch import
bughelp wanted

Repository metrics

Stars
 (15,497 stars)
PR merge metrics
 (Avg merge 12h 56m) (52 merged PRs in 30d)

Description

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

Contributor guide