前言
在团队中,提交信息的清晰明了非常重要,下面介绍怎么在commit过程中对commit message进行检测
工具
1.husky
2.commitlint
安装commitlint
npm install --save-dev @commitlint/{cli,config-conventional}
安装husky
npm install husky --save-dev
npm set-script prepare "husky install"
npm run prepare
添加husky钩子
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'\
配置提交规范
commitlint推荐我们使用 config-conventional 配置去写 commit,
新建.commitlintrc.js文件
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['update', 'feature', 'fixbug', 'refactor', 'docs', 'chore', 'style', 'revert']
],
'type-case': [0],
'type-empty': [0],
'scope-empty': [0],
'scope-case': [0],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never'],
'header-max-length': [0, 'always', 72]
}
};
更多配置方式参考commitlint官方文档:commitlint.js.org/
commit 提交规范
注意冒号后面有空格
git commit -m <type>(<scope>): <subject>