Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git规范化提交配置(commitlint) #22

Open
wuqiong7 opened this issue Dec 2, 2019 · 0 comments
Open

Git规范化提交配置(commitlint) #22

wuqiong7 opened this issue Dec 2, 2019 · 0 comments

Comments

@wuqiong7
Copy link
Owner

wuqiong7 commented Dec 2, 2019

如何使用

首先要装依赖包

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

在根目录下添加文件commitlint.config.js

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

package.json中配置husky钩子

{
  "scripts": {
    "commitmsg": "commitlint -E GIT_PARAMS"
  }
}

完事!

配置详情

rule配置说明: 由name和配置数组组成

<type>(<scope>): <subject> # 注意冒号后面有空格
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

name:[0, 'always', 72]

  • Level:[0, 1, 2] 0: disable,1: warning,2:error
  • Applicable: always|never
  • Value

type-enum

常规推荐的常用type,当然不局限于此,可以随意定义

  • upd:更新某功能(不是 feat, 不是 fix)
  • feat:新功能(feature)
  • fix:修补bug
  • docs:文档(documentation)
  • style: 格式(不影响代码运行的变动)
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:增加测试
  • chore:构建过程或辅助工具的变动

其他

  • type-empty # 类型是否为空
  • scope-case # 修改范围的大小写
  • subject-case # subject的大小写
  • subject-empty # subject是否为空
  • subject-full-stop # subject的结尾形式
  • header-max-length # 长度限制
'type-case': [2, 'always', ['upper-case']] # 大写
'type-case': [2, 'never', ['upper-case']] # 小写
'subject-full-stop': [2, 'never', '.']   # subject不能一'.'结尾
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant