使用husky規(guī)范項(xiàng)目的commit message

該方法已過(guò)時(shí),請(qǐng)看 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 這些插件支持開(kāi)發(fā)者在 commitlintrc.js 或者 json 文件里面進(jìn)行自定義配置。

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

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

配置提交規(guī)范

新建.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  -->
}

寫得比較粗糙,記錄下來(lái)只是為了方便后續(xù)新建項(xiàng)目的初始化,跟做一次記錄

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容