Skip to content

fix: type detection issue when an exclamation mark is added to the commit (in case of custom issue prefixes) #4640

@thebit94dev

Description

@thebit94dev

Steps to Reproduce

When attempting to enable validation for issue/ticket numbers as described here: https://commitlint.js.org/reference/examples.html#validate-for-issue-ticket-numbers

"parserPreset": {
      "parserOpts": {
        "issuePrefixes": ["PROJ-"],
      },
    },

Current Behavior

Commitlint encounters a type detection problem when an exclamation mark (!) is included in the commit header.
For example:

commitlint...............................................................Failed
- hook id: commitlint
- exit code: 1
⧗   input: 

feat!: some description

Refs: PROJ-123
BREAKING CHANGE: some description

✖   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

Expected Behavior

There should be a way to add or override the issuePrefixes without needing to replace the entire parserPreset configuration.
Also the documentation should be updated: https://commitlint.js.org/reference/examples.html#validate-for-issue-ticket-numbers.
Additionally I found no way/rule to enforce that the issues must only exists in the footer section (currently putting it anywhere in the commit would pass the issue detection)

Current workaround:
Since I am extending the default configuration with "extends": ["@commitlint/config-conventional"], I copied the entire parser configuration from here: https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-conventionalcommits/src/parser.js
This approach works, but I am unsure if it is correct or if other attributes beyond parserOpts inside parserPreset also need to be copied.

  "parserPreset": {
    "parserOpts": {
      "headerPattern": "^(\\w*)(?:\\((.*)\\))?!?: (.*)$",
      "breakingHeaderPattern": "^(\\w*)(?:\\((.*)\\))?!: (.*)$",
      "headerCorrespondence": [
        "type",
        "scope",
        "subject"
      ],
      "noteKeywords": [
        "BREAKING CHANGE",
        "BREAKING-CHANGE"
      ],
      "revertPattern": "^(?:Revert|revert:)\\s\"?([\\s\\S]+?)\"?\\s*This reverts commit (\\w*)\\.",
      "revertCorrespondence": [
        "header",
        "hash"
      ],
      "issuePrefixes": [
        "PROJ-"
      ]
    }
  }

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Context

No response

commitlint --version

20.4.3

git --version

2.43.0

node --version

24.11.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions