forked from zhongyidian/super_video
87 lines
1.7 KiB
Markdown
87 lines
1.7 KiB
Markdown
# Husky 配置说明
|
|
|
|
## 已安装的依赖
|
|
|
|
- `husky`: Git hooks 管理工具
|
|
- `lint-staged`: 对暂存文件运行 linters
|
|
- `@commitlint/cli`: Commit 信息验证工具
|
|
- `@commitlint/config-conventional`: 约定式提交规范
|
|
|
|
## 配置内容
|
|
|
|
### 1. Pre-commit 钩子
|
|
|
|
在每次 commit 前自动执行:
|
|
|
|
- ESLint 检查和自动修复
|
|
- Prettier 代码格式化
|
|
|
|
### 2. Commit-msg 钩子
|
|
|
|
验证 commit 信息格式,必须符合约定式提交规范:
|
|
|
|
**格式**: `<type>(<scope>): <subject>`
|
|
|
|
**允许的 type 类型**:
|
|
|
|
- `feat`: 新功能
|
|
- `fix`: 修复 bug
|
|
- `docs`: 文档更新
|
|
- `style`: 代码格式调整
|
|
- `refactor`: 代码重构
|
|
- `perf`: 性能优化
|
|
- `test`: 测试相关
|
|
- `build`: 构建相关
|
|
- `ci`: CI/CD 相关
|
|
- `chore`: 其他杂务
|
|
- `revert`: 回滚提交
|
|
|
|
**规则**:
|
|
|
|
- subject 最大长度: 50 字符
|
|
- body 每行最大长度: 100 字符
|
|
- subject 不能使用句首大写、帕斯卡命名等格式
|
|
|
|
### 3. Prettier 配置
|
|
|
|
已创建 `.prettierrc` 配置文件,统一代码格式:
|
|
|
|
- 不使用分号
|
|
- 使用单引号
|
|
- 缩进 2 个空格
|
|
- 行宽限制 100 字符
|
|
- 不使用尾随逗号
|
|
|
|
## 使用方法
|
|
|
|
### 正常提交
|
|
|
|
```bash
|
|
git add .
|
|
git commit -m "feat: 添加新功能"
|
|
```
|
|
|
|
### 如果 commit 信息不符合规范
|
|
|
|
```bash
|
|
git commit -m "invalid message"
|
|
# 会提示错误并要求修改
|
|
```
|
|
|
|
### 手动运行检查
|
|
|
|
```bash
|
|
# 检查代码格式
|
|
npx lint-staged
|
|
|
|
# 检查 commit 信息
|
|
echo "feat: 测试" | npx commitlint
|
|
```
|
|
|
|
## 注意事项
|
|
|
|
1. 确保使用 `nvm use 22.14` 切换到正确的 Node.js 版本
|
|
2. 使用 `pnpm` 作为包管理器
|
|
3. 所有代码在提交前会自动进行格式化和检查
|
|
4. 如果检查失败,commit 会被阻止,需要修复后重新提交
|