commitlint-config-hfex
1.0.2 • Public • Published git commit 规范
扩展的规则是 描述必须要存在 7个或以上的中文字符
rules: {
'subject-zh-min-count': (parsed, when, value) => {
const zhCharRegexp = /[\u4e00-\u9fa5]/,
enCharRegexp = /[a-zA-Z]/,
minCount = value || 7,
subject = parsed.subject || '';
let count = 0,
valid = false;
for (const c of subject) {
if (zhCharRegexp.test(c)) {
count += 1;
}
if (enCharRegexp.test(c)) {
// 2 个英文字符当做一个中文字符
count += 0.5;
}
if (count >= minCount) {
valid = true;
break;
}
}
return [valid, `描述必须要存在 ${minCount} 个或以上的中文字符`];
}
}
install package
pnpm install husky hfex-commitlint-config @commitlint/cli -D
init husky
add commit-msg
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
在项目根目录新增配置文件commitlint.config.js
module.exports = {
extends: [require.resolve('hfex-commitlint-config')],
};
运行
git add .
git commit -m 'xxxx'
Versions
Version | Downloads (Last 7 Days) | Tag |
---|
1.0.2 | 5 | latest |
Version History
Version | Downloads (Last 7 Days) | Published |
---|
1.0.2 | 5 | |
Package Sidebar
Install
npm i commitlint-config-hfex
Weekly Downloads