[TBID:ECX-9138] feat(commitlint): add TBID header rule and update config for commit message validation

This commit is contained in:
lukaijie
2026-07-03 13:55:19 +08:00
parent b297512184
commit af925aa2ae
2 changed files with 59 additions and 27 deletions

14
commitlint-tbid-plugin.js Normal file
View File

@@ -0,0 +1,14 @@
module.exports = {
rules: {
'tbid-header': (parsed, when = 'always') => {
const matches =
typeof parsed.header === 'string' && /^\[TBID:[A-Za-z0-9]+-\d+\]\s.+/.test(parsed.header)
const negated = when === 'never'
return [
negated ? !matches : matches,
'commit message must start with [TBID:PROJECT-123] description'
]
}
}
}

View File

@@ -1,43 +1,61 @@
const TBID_HEADER = /^\[TBID:([A-Za-z0-9]+-\d+)\]\s(?:(\w+)(?:\(([^)]*)\))?(?::|\s)\s*)?(.+)$/
module.exports = {
extends: ['@commitlint/config-conventional', 'cz'],
// 关闭默认忽略(含 semver release否则无 TBID 的 chore(release): x.x.x 会被跳过
defaultIgnores: false,
// 保留 merge / revert 等系统提交的豁免,不要求 TBID
ignores: [
(message) => /^Merge pull request/m.test(message),
(message) => /^Merge tag /m.test(message),
(message) => /^Revert /m.test(message),
(message) => /^(fixup|squash)!/m.test(message),
(message) => /^Merged PR /m.test(message),
(message) => /^Merge remote-tracking branch/m.test(message),
(message) => /^Automatic merge/m.test(message),
(message) => /^Auto-merged /m.test(message)
],
plugins: [require('./commitlint-tbid-plugin')],
parserPreset: {
parserOpts: {
headerPattern: TBID_HEADER,
headerCorrespondence: ['tbid', 'type', 'scope', 'subject']
}
},
rules: {
'tbid-header': [2, 'always'],
'type-enum': [
2,
'always',
[
'feature', // 新功能feature
'bug', // 此项特别针对bug号用于向测试反馈bug列表的bug修改情况
'fix', // 修补bug
'ui', // 更新 ui
'docs', // 文档documentation
'style', // 格式(不影响代码运行的变动)
'perf', // 性能优化
'release', // 发布
'deploy', // 部署
'refactor', // 重构即不是新增功能也不是修改bug的代码变动
'test', // 增加测试
'chore', // 构建过程或辅助工具的变动
'revert', // feat(pencil): add graphiteWidth option (撤销之前的commit)
'merge', // 合并分支, 例如: merge前端页面 feature-xxxx修改线程地址
'build' // 打包
'feat',
'feature',
'bug',
'fix',
'ui',
'docs',
'style',
'perf',
'release',
'deploy',
'refactor',
'test',
'chore',
'revert',
'merge',
'build',
'ci',
'workflow'
]
],
// <type> 格式 小写
'type-case': [2, 'always', 'lower-case'],
// <type> 不能为空
'type-empty': [2, 'never'],
// <scope> 范围不能为空
'scope-empty': [2, 'never'],
// <scope> 范围格式
// type 可选,兼容 [TBID:xxx] Bug修复 这类 GitLab 格式
'type-empty': [0],
'scope-empty': [0],
'scope-case': [0],
// <subject> 主要 message 不能为空
'subject-empty': [2, 'never'],
// <subject> 以什么为结束标志,禁用
'subject-full-stop': [0, 'never'],
// <subject> 格式,禁用
'subject-case': [0, 'never'],
// <body> 以空行开头
'body-leading-blank': [1, 'always'],
'header-max-length': [0, 'always', 72]
'header-max-length': [0, 'always', 100]
}
}