1
0
Files
nex/openspec/changes/backend-code-lint/specs/pre-commit-hook/spec.md

55 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Pre-commit Hook
## Purpose
定义基于 lefthook 的 pre-commit hook 配置,在 git commit 时自动运行 lint 检查,拦截违规代码提交。
## ADDED Requirements
### Requirement: lefthook 配置
系统 SHALL 通过 `lefthook.yml` 配置 pre-commit hook。
#### Scenario: 配置文件位置
- **WHEN** 配置 lefthook
- **THEN** 配置文件 SHALL 位于项目根目录 `lefthook.yml`
#### Scenario: pre-commit hook 安装
- **WHEN** 开发者首次克隆项目
- **THEN** 运行 `lefthook install` SHALL 安装 git hooks
- **THEN** hooks SHALL 自动注册到 .git/hooks/
### Requirement: Go 文件变更触发 lint
系统 SHALL 在 Go 文件变更时自动运行 golangci-lint。
#### Scenario: 检测到 Go 文件变更
- **WHEN** git commit 中包含 backend/**/*.go 文件的变更
- **THEN** SHALL 自动运行 golangci-lint
#### Scenario: 增量检查
- **WHEN** 运行 lint
- **THEN** SHALL 只检查 staged 文件(使用 --new-from-rev HEAD
- **THEN** SHALL NOT 检查整个代码库
#### Scenario: lint 通过
- **WHEN** golangci-lint 检查通过
- **THEN** commit SHALL 正常完成
#### Scenario: lint 失败
- **WHEN** golangci-lint 检查发现违规
- **THEN** commit SHALL 被拒绝
- **THEN** SHALL 显示具体的违规信息和修复建议
#### Scenario: 无 Go 文件变更
- **WHEN** git commit 不包含 Go 文件变更
- **THEN** SHALL NOT 运行 golangci-lint
- **THEN** commit SHALL 正常完成