conventional-changelog/commitlint

fix: can't set headerPattern from YAML configuration files

Fermée

#3 487 ouverte le 6 janv. 2023

 (7 commentaires) (0 réaction) (0 personne assignée)TypeScript (896 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (15 497 étoiles)
Métriques de merge PR
 (Merge moyen 12h 56m) (52 PRs mergées en 30 j)

Description

Expected Behavior

I use YAML configuration and try to set headerPattern like this:

extends:
  - '@commitlint/config-conventional'
parserPreset:
  parserOpts:
    headerPattern: '/^([^0-9]\w*)(?:\(([^0-9].*)\))?!?: (.*)$/' 

This should avoid scope starting with a digit:

$ echo 'fix(123): foo' | commitlint --verbose
⧗   input: fix(123): foo
✖   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

Current Behavior

This load the headerPattern as a string instead of a regular expression:

$ commitlint --print-config | grep headerPattern
    parserOpts: { headerPattern: '/^([^0-9]\\w*)(?:\\(([^0-9].*)\\))?!?: (.*)$/' }

It looks like the scope starting with a digit is catch:

$ echo 'fix(123): foo' | commitlint --verbose
⧗   input: fix(123): foo
✖   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

But it catch everything since headerPattern is not a regex:

echo 'fix(bar): foo' | commitlint --verbose
⧗   input: fix(bar): foo
✖   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

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

The pattern options should be converted to regular expression.

Steps to Reproduce

1. define the following configuration `.commitlintrc.yaml`
   
   extends:
     - '@commitlint/config-conventional'
   parserPreset:
     parserOpts:
       headerPattern: '/^([^0-9]\w*)(?:\(([^0-9].*)\))?!?: (.*)$/'
   
2. execute the following command which should fail: `echo 'fix(123): foo' | commitlint --verbose`
3. execute the following command which should pass: `echo 'fix(bar): foo' | commitlint --verbose`

Context

Note that replacing the .commitlintrc.yaml with the following commitlint.config.js is working:

module.exports = {
    extends: ['@commitlint/config-conventional'],
    parserPreset: {
        parserOpts: {
            headerPattern: /^([^0-9]\w*)(?:\(([^0-9].*)\))?!?: (.*)$/,
        }
    }
};

commitlint --version

@commitlint/cli@14.4.0

git --version

2.38.2

node --version

v19.3.0

Guide contributeur