Install commitlint
npm install --save-dev @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
或者配置可以在被定義.commitlintrc.js,.commitlintrc.json或者.commitlintrc.yml文件或commitlint在字段package.json
例如在package.json中加入"commitlint": { "extends": [ "@commitlint/config-conventional" ], "rules": { "type-enum": [ 2, "always", [ "feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert" ] ], "type-case": [ 2, "always", [ "lower-case" ] ], "type-empty": [ 2, "never" ], "scope-empty": [ 2, "never" ], "scope-case": [ 2, "always", [ "lower-case", "upper-case", "camel-case", "kebab-case", "pascal-case", "sentence-case", "snake-case", "start-case" ] ], "subject-case": [ 2, "always", [ "lower-case", "upper-case", "camel-case", "kebab-case", "pascal-case", "sentence-case", "snake-case", "start-case" ] ], "subject-empty": [ 2, "never" ], "subject-full-stop": [ 2, "never" ], "header-max-length": [ 2, "always", 72 ] } }
Install husky
npm install --save-dev husky
This allows us to add?git hooks?directly into our?package.json?via the?husky.hooks?field.
// package.json
"husky": {
????????"hooks": {
????????????"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
????????}?
? }
commit規(guī)范
Commit message格式
type(scope?): subject?
注意冒號(hào)后面有空格。
type
用于說明 commit 的類別巡语,只允許使用下面7個(gè)標(biāo)識(shí)鬓催。
feat:新功能(feature)
fix:修補(bǔ)bug
docs:文檔(documentation)
style: 格式(不影響代碼運(yùn)行的變動(dòng))
refactor:重構(gòu)(即不是新增功能厂榛,也不是修改bug的代碼變動(dòng))
test:增加測(cè)試
chore:構(gòu)建過程或輔助工具的變動(dòng)
scope[optional]
表示改動(dòng)的模塊或者文件或者功能
subject
提交簡(jiǎn)短的問題描述
規(guī)則
規(guī)則由名稱和配置數(shù)組組成赏僧。配置數(shù)組包含:
級(jí)別?[0..2]:0禁用規(guī)則庭敦。因?yàn)?它將被視為2錯(cuò)誤警告匿情。
適用?always|never:never顛倒規(guī)則兰迫。
值:用于此規(guī)則的值。
參考鏈接:?commitlint官網(wǎng)