conventional-changelog/commitlint

fix: can't set headerPattern from YAML configuration files

Fechada

#3.487 aberto em 6 de jan. de 2023

 (7 comentários) (0 reação) (0 responsável)TypeScript (896 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (15.497 estrelas)
Métricas de merge de PR
 (Mesclagem média 12h 56m) (52 fundiu PRs em 30d)

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

Guia do colaborador