commitlint配置

不知道是不是node版本问题或者vue版本问题,网上的查了几十篇没有一个能成功的,好不容易琢磨出来了正确思路,凭着记忆大概记录了一下

commitizen

  1. npm install -g commitizen

  2. npm install -D commitizen cz-conventional-changelog
    网上有提到commitizen init cz-conventional-changelog --save-dev --save-exact但输入会显示让用npm包初始化

 "config": {
    "commitizen": {
      "path": "node_modules/cz-conventional-changelog"
    }
  }

经过尝试,这一步可有可无

git cz
? Select the type of change that you're committing: (Use arrow keys)
> feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  refactor: A code change that neither fixes a bug nor adds a feature
  perf:     A code change that improves performance
  test:     Adding missing tests or correcting existing tests
(Move up and down to reveal more choices)

如果这一步不能出现,就反反复复安装commitizen,一样的代码我执行了两遍才安装成功

conmmitlint

  1. npm install -g @commitlint/cli @commitlint/config-conventional

  2. npx husky-init
    安装husky,此步会出现新的.husky文件夹,并生成一个pre-commit的文件(示例挂钩),内容是“npm test”,意思是在提交之前自动执行"npm test"命令,可以修改成自己想要执行的命令,多个命令之间使用 && 分隔
    我写的是,代码美化和eslint

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint &&npm run format
  1. 添加commit-msg钩子,验证git commit的message是否符合commitlint的规范

这一步会出现commit-msg的文件

  1. Husky 添加一个 Hook

npx husky add .husky/pre-commit “npm run lint”

  1. 然后在根目录创建配置文件 .commitlintrc.cjs,而不是别的博客说的cofig.js,亲测无效

module.exports = {
extends: [“@commitlint/config-conventional”],
};

  1. 然后把 commitlint 命令也添加 Husky Hook。运行命令:
npx husky add .husky/commit-msg "npx --no-install commitlint -e $HUSKY_GIT_PARAMS"

最后基本才算配置完毕

git commit -m ‘foo: test’测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值