commitlint 无法使范围可选

Gau*_*hah 5 commit github github-actions

我正在尝试使用问题前缀来使我的提交格式如下所述

JIRA-ID: type(scope): Subject
Run Code Online (Sandbox Code Playgroud)

范围应该是可选的。这意味着以下是有效的消息

  • AAAA-12:修复(测试):修复了失败的测试

  • AAAA-12:修复:修复了失败的测试

以下是我的commitlint.config.js的样子

module.exports = {
    extends: ['@commitlint/config-conventional'],
    parserPreset: {
           parserOpts: {
              headerPattern: /^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)\((\w*)\):\s(.*)$/,
              headerCorrespondence: ["type", "scope", "subject"],
              issuePrefixes: ["^[A-Z]{1,4}-[0-9]{1,4}"],
              referenceActions: ["xxx-"] // (!!)
            }
      },
 rules: {
        'references-empty': [2, 'never'],
       'scope-empty': [1, 'never'],
      ...
     ... 
}
}
Run Code Online (Sandbox Code Playgroud)

以下消息似乎无效。

AAAA-12: fix: fixed the failing test
Run Code Online (Sandbox Code Playgroud)

它迫使我使用空括号,如下所述。

AAAA-12(): fix: fixed the failing test
Run Code Online (Sandbox Code Playgroud)

rid*_*tun 1

你的 headerPattern 是错误的。尝试下面的正则表达式:

/^[A-Z]{1,4}-[0-9]{1,4}:\s(\w*)(\((\w+)\))?:\s(.*)$/
Run Code Online (Sandbox Code Playgroud)

您还可以在线测试此正则表达式:https://regex101.com/r/MtG7sy/2