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 ]
}
}
npm install --save-dev huskyjavascript
This allows us to add git hooks directly into our package.json via the husky.hooks field.java
// package.jsongit
"husky": {github
"hooks": {npm
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"json
} 數組
}工具
type(scope?): subject 測試
注意冒號後面有空格。ui
用於說明 commit 的類別,只容許使用下面7個標識。
feat:新功能(feature)
fix:修補bug
docs:文檔(documentation)
style: 格式(不影響代碼運行的變更)
refactor:重構(即不是新增功能,也不是修改bug的代碼變更)
test:增長測試
chore:構建過程或輔助工具的變更
表示改動的模塊或者文件或者功能
提交簡短的問題描述
規則由名稱和配置數組組成。配置數組包含:
級別 [0,1,2]:0禁用規則 1報warning 2.報error。
適用 always|never:never顛倒規則。
值:用於此規則的值。
參考連接: commitlint官網