使用commitlint规范git提交

在我们开始一个项目的时候通常会用eslint去规范js代码。我们还可以用一些命令行工具去规范我们的git提交信息以及在每次git操作过程中执行一些测试,最快可以依据git提交信息生成CHANGELOG文件

commitlint: git 提交信息规范与验证
husky: 使ghook更容易
standard-version: 自动生成CHANGELOG 并发布版本

安装

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

配置

commitlint
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']
  }}; 

Standard-version 和 husky

// 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"
 }

使用

具体参考相应官网
    原文作者:Neil
    原文地址: https://segmentfault.com/a/1190000015691105
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞