使用husky规范项目的commit message

该方法已过时,请看 https://juejin.cn/post/6988116616923840549 这里

需要先安装 husky

husky 的功能让 git 的钩子变得容易,可以有效阻止不好的 git commit, git push 等等;


npm install husky --save-dev

安装 @commitlint/config-conventional @commitlint/cli

@commitlint/config-conventional 和 @commitlint/cli 这些插件支持开发者在 commitlintrc.js 或者 json 文件里面进行自定义配置。

npm 地址: https://www.npmjs.com/package/@commitlint/config-conventional

npm install --save-dev @commitlint/config-conventional @commitlint/cli

配置提交规范

新建.commitlintrc.js 文件

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      ['upd', 'feat', 'fix', 'refactor', 'docs', 'chore', 'style', 'revert']
    ],
    'type-case': [0],
    'type-empty': [0],
    'scope-empty': [0],
    'scope-case': [0],
    'subject-full-stop': [0, 'never'],
    'subject-case': [0, 'never'],
    'header-max-length': [0, 'always', 72]
  }
};

新增钩子

package.json文件里面去修改

{
  "name": "your packages name",
  "author": "Fernando",
  "private": true,
  "scripts": {},
  "dependencies": {},
  <!-- start  -->
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E $HUSKY_GIT_PARAMS",
      "pre-commit": "npm run lint"
    }
  }
  <!-- end  -->
}

写得比较粗糙,记录下来只是为了方便后续新建项目的初始化,跟做一次记录

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容