前言
commitlint
: https://commitlint.js.org/
guides-local-setup
: https://commitlint.js.org/#/guides-local-setup
config-conventional
: config-conventional
内容
安装配置
# Install and configure if needed npm install --save-dev @commitlint/{cli,config-conventional} # For Windows: npm install --save-dev @commitlint/config-conventional @commitlint/cli # Configure commitlint to use conventional config # 这里windows下有坑,最好直接创建commitlint.config.js然后复制进去 | 当然也可以创建后再调整编码和换行符 # 使用echo创建的时候默认是UTF-16LE,具体请看上面的Windows PowerShell中的字符编码 echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
husky
安装
# Install Husky v6 npm install husky --save-dev # or yarn add husky --dev # Activate hooks npx husky install # or yarn husky install
配置
npx husky add .husky/commit-msg "npx --no -- commitlint --edit ${1}"
测试
## 错误示例 PS C:\Users\WangYang\Documents\Project\electron-vite-vue> git commit -m "commitlint" → No staged files match any configured task. ⧗ input: commitlint ✖ subject may not be empty [subject-empty] ✖ type may not be empty [type-empty] ✖ found 2 problems, 0 warnings ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint husky - commit-msg hook exited with code 1 (error) ## 正确示例 PS C:\Users\WangYang\Documents\Project\electron-vite-vue> git commit -m "chore: commitlint" → No staged files match any configured task. [main ee32252] chore: commitlint 5 files changed, 4903 insertions(+), 5629 deletions(-) create mode 100644 .husky/commit-msg create mode 100644 commitlint.config.js rewrite pnpm-lock.yaml (98%)
学无止境,谦卑而行.