项目添加commitlint提交验证
安装
- 如果根目录没有
package.json
,先添加,如果请跳过
pnpm init
- 安装依赖
pnpm add @kvuse/commitlint-config @commitlint/cli -D
使用
使用命令添加配置文件
cd node_modules/@kvuse/commitlint-config
pnpm run preinstall
执行命令成功提示
> @kvuse/commitlint-config@1.1.0 preinstall /Users/liukai/Documents/work/husky-demo/node_modules/.pnpm/@kvuse+commitlint-config@1.1.0/node_modules/@kvuse/commitlint-config
> node prepare
添加.commitlintrc.json成功
添加.husky成功
添加提交eslint
验证
-
package.json
添加lint
如果有请忽略
"scripts": { "lint": "eslint ." },
-
.husky
添加npm run lint
命令// .husky/commit-msg #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" npx --no -- commitlint --edit "$1" npm run lint
测试
git add .
git commit -m 'Feat更'
如果出现以下报错就成功了
⧗ input: Feat更
✖ 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)
规则
[
'feat', // 新功能(feature)
'fix', // 修补bug
'docs', // 文档(documentation)
'style', // 格式(不影响代码运行的变动)
'refactor', // 重构
'test', // 增加测试
'revert', // 回滚
'config', // 构建过程或辅助工具的变动
'chore', // 其他改动
],
- 开头必须有上述字段,例如:
feat: 添加xx功能
- 提交内容不能小于三个字符
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
2017-09-06 总结一些常用的正则表达式
2017-09-06 element ui 弹出框在关闭后再打开验证的错误显示问题