前端工程化之commit规范(代码提交规范)

其实commit规范不管是前端还是后端也好,我觉得吧,在任何的工程化的项目中都是不可或缺的部分啦,commit 提交不规范,项目维护和管理起来是极其麻烦的,毕竟每个人都具有自己的个性,commit message的格式也是参差不齐

git 可以帮我们很好地管理代码,但是在多人合作的时候,经常会碰到各种随意的 commit message,当你需要会看 commit message 的时候,就会很头疼。
幸运的是我们可以使用工具去处理掉这个问题,不让这种小问题影响到项目的进展

第一步:安装commitlint插件和husky插件 (规范)

npm install @commitlint/cli @commitlint/config-conventional -D
npm install husky -D

二步:将husky进行初始化

// 一定要需要git init 初始化
npx husky install

第三步:生成husky配置文件

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

// 如果生成文件失败,则。
1. npx husky add .husky/commit-msg
2,将 'npx --no-install commitlint --edit $1' 粘贴到husky下的 commit-msg 文件下

第四步:生成commitlint配置文件

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

// 在提交commit时可能会报错: SyntaxErroe: Invalid or unexpected token
// 解决办法:
// 这是因为配置文件的编码格式不正确:更改vscode下方编码格式改成 UTF-8

第五步:commitlint配置文件内配置提交规则

// 将以下内容替换 commitlint.config.js 内容
module.exports = {
  extends: [
    "@commitlint/config-conventional"
  ],
// # 提交格式(注意冒号后面有空格)
// # git commit -m <type>[optional? scope]: <description>
// 例:git commit -m 'feat: 测试' 
  rules: {
    'type-enum': [2, 'always', [
      'upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert'
     ]],
    'type-case': [0],
    'type-empty': [2, 'never'],
    'scope-empty': [0],
    'scope-case': [0],
    'subject-full-stop': [0],
    'subject-empty': [2, 'never'],
    'subject-case': [0],
    'header-max-length': [0]
  }
};

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@前端小菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值