使用commitlint规范git提交

commitlint: git 提交信息规范与验证

husky: 使ghook更容易

standard-version: 自动生成CHANGELOG 并发布版本

安装

1
2
3
npm install --save-dev @commitlint/{config-conventional,cli}
npm i --save-dev standard-version
npm install husky --save-dev

配置

  1. commitlint
1
2
3
4
5
6
7
8
9
10
11
12
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
// commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', [
"feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"
]],
'scope-empty': [2, 'never'],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never']
}};
  1. tandard-version 和 husky
1
2
3
4
5
6
7
8
9
10
11
12
// package.json
"scripts": {
"lint": "eslint .",
"commitmsg": "commitlint -e $GIT_PARAMS",
"release": "standard-version",
"validate": "npm prune",
"pre-commit": "npm run lint",
"pre-push": "npm run validate",
"npmi": "npm i",
"post-merge": "npm run npmi",
"post-rewrite": "npm run npmi"
}