git hook

git commit-msg
可以用来规范标准格式,并且可以按需要指定是否要拒绝本次提交

git pre-commit
会在提交前被调用,并且可以按需要指定是否要拒绝本次提交

使用husky + commitlint 检查提交代码
commitlint:用于检查提交信息
husky 是gits hooks工具

commitlint
1.安装依赖
npm install --save-dev @commitlint/config-conventional@12.1.4 @commitlint/cli@12.1.4

2.创建 commitlint.config.js文件

echo "module.exports = {extends:['@commitlint/config-conventional']}" > commitlint.config.js

3.打开 commitlint.config.js 增加配置项

module.exports = {
  // 继承的规则
  extends: ['@commitlint/config-conventional'],
  // 定义规则类型
  rules: {
    // type 类型定义,表示 git 提交的 type 必须在以下类型范围内
    'type-enum': [
      2,
      'always',
      [
        'feat', // 新功能 feature
        'fix', // 修复 bug
        'docs', // 文档注释
        'style', // 代码格式(不影响代码运行的变动)
        'refactor', // 重构(既不增加新功能,也不是修复bug)
        'perf', // 性能优化
        'test', // 增加测试
        'chore', // 构建过程或辅助工具的变动
        'revert', // 回退
        'build' // 打包
      ]
    ],
    // subject 大小写不做校验
    'subject-case': [0]
  }
}

husky
1.安装 依赖
npm install husky@7.0.1 --save-dev

2启动hooks,生成 .husky文件
npx husky install

3.在package.json中生成prepare指令
npm set-script prepare “husky install”

4.执行 prepare指令
npm run prepare

5.添加 commitlint的hook到husky中,并指令在 commit-msg的hooks下执行 npx --no-install commitlint --edit “$1”

npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1" '

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值