commitlint规范git提交

先附上文档

husky:https://typicode.github.io/husky/#/
commitlint:https://github.com/conventional-changelog/commitlint

安装

cnpm i @commitlint/cli @commitlint/config-conventional husky@4.2.5 -D

配置package.json文件

package.json文件
{..."husky": {"hooks": {"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}},
}

生成文件

echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
module.exports = {ignores: [(commit) => commit.includes('init')], //提交过程中忽略有init的字符串extends: ['@commitlint/config-conventional'],parserPreset: {//提交解析规则parserOpts: {headerPattern: /^【(\w*|[\u4e00-\u9fa5]*)】(.*)/,headerCorrespondence: ['type', 'subject'],},},rules: {'body-leading-blank': [2, 'always'], //body上面要有换行'footer-leading-blank': [1, 'always'], //footer上面要有换行'header-max-length': [2, 'always', 108], //header最大108个字符'subject-empty': [2, 'never'], //subject位不能为null'type-empty': [2, 'never'], //type位不能为null'type-enum': [//type提交规则2,'always',['feat','fix','perf','style','docs','test','refactor','chore','revert','wip','types',],],},};

测试在这里插入图片描述
正确
在这里插入图片描述

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注