npm install husky @commitlint/cli @commitlint/config-conventional -D
npm set-script prepare "husky install"
npm run prepare
npx husky add .husky/pre-commit "npx lint-staged --allow-empty $1"
git add .husky/pre-commit
npx husky add .husky/commit-msg "npx --no-install commitlint --edit $1"
- 根目录新建
commitlint.config.js
module.exports = {
extends: ["@commitlint/config-conventional"],
// 自定义规则
rules: {
"type-enum": [
2,
"always",
[
"bug", // 此项特别针对bug号,用于向测试反馈bug列表的bug修改情况
"feat", // 新功能(feature)
"fix", // 修补bug
"docs", // 文档(documentation)
"style", // 格式(不影响代码运行的变动)
"refactor", // 重构(即不是新增功能,也不是修改bug的代码变动)
"perf", // 性能优化
"test", // 增加测试
"chore", // 构建过程或辅助工具的变动
"revert", // feat(pencil): add ‘graphiteWidth’ option (撤销之前的commit)
"merge", // 合并分支, 例如: merge(前端页面): feature-xxxx修改线程地址
"build", // 打包
],
],
// //0=>disable,1=>warning,2=>error
// "type-empty": [2, "error"],
// "scope-empty": [0],
// "scope-case": [0],
// // subject 大小写不做校验
// "subject-case": [0],
// // 提交内容不能为空
// "subject-empty": [2, "always"],
// "subject-full-stop": [0],
// "type-case": [0],
// "header-max-length": [2, "always", 72],
},
};
{
"src/**/*.{js,vue}": ["prettier --write", "eslint --fix", "git add"]
}
网友评论