Skip to content

Commit 19e32d5

Browse files
authored
Merge pull request #187 from ThreeFish-AI/vk/8389-pre-commit-hooks
feat(pre-commit): 配置 Pre-commit Hooks,实现本地 commit 前自动 lint/format 守护
2 parents 3a6b059 + c2ee552 commit 19e32d5

8 files changed

Lines changed: 166 additions & 8 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,3 @@ jobs:
193193
with:
194194
skip-existing: true
195195
verbose: true
196-

‎.pre-commit-config.yaml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# =============================================================================
2+
# coding-proxy: Pre-commit Hooks Configuration
3+
# =============================================================================
4+
# 目的: 在代码提交前自动执行 Ruff lint/format 及通用卫生检查,作为 CI 的前置守护
5+
#
6+
# 设计决策:使用 local hook(language: system + uv run)而非 astral-sh/ruff-pre-commit
7+
# - 遵循 Single Source of Truth 原则:Ruff 版本由 uv.lock 唯一管控,消除版本漂移
8+
# - 与 CI 命令形态完全镜像(uv run ruff check/format)
9+
# - 符合 AGENTS.md 包管理规范(统一使用 uv)
10+
#
11+
# 安装:uv run pre-commit install
12+
# 手动全量检查:uv run pre-commit run --all-files
13+
# =============================================================================
14+
15+
minimum_pre_commit_version: "4.0.0"
16+
17+
repos:
18+
# ---------------------------------------------------------------------------
19+
# 通用代码卫生检查(pre-commit-hooks 官方钩子集)
20+
# 轻量级、无额外依赖、执行极快
21+
# ---------------------------------------------------------------------------
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v5.0.0
24+
hooks:
25+
- id: trailing-whitespace # 去除行尾空白
26+
- id: end-of-file-fixer # 确保文件以换行符结尾
27+
- id: check-yaml
28+
args: ["--unsafe"] # 兼容 GitHub Actions ${{ }} 表达式语法
29+
- id: check-toml # 校验 TOML 语法(pyproject.toml)
30+
- id: check-merge-conflict # 阻止提交含未解决 merge conflict 标记的文件
31+
- id: check-added-large-files
32+
args: ["--maxkb=1024"] # 阈值 1MB(assets/dashboard-v0.2.3.png 为 944KB)
33+
34+
# ---------------------------------------------------------------------------
35+
# Ruff: local hook,直接调用 uv 安装的 Ruff(与 CI 版本完全一致)
36+
# 前置条件:uv sync --dev 已执行
37+
# ---------------------------------------------------------------------------
38+
- repo: local
39+
hooks:
40+
# 对应 CI: uv run ruff check .
41+
# --fix: 自动修复安全可修复问题(isort、UP 现代化等),降低开发摩擦
42+
# --exit-non-zero-on-fix: 修复后返回非零码,触发 git 重新暂存已修复文件
43+
- id: ruff-lint
44+
name: Ruff (lint + auto-fix)
45+
language: system
46+
entry: uv run ruff check --fix --exit-non-zero-on-fix
47+
types_or: [python, pyi]
48+
require_serial: false
49+
50+
# 对应 CI: uv run ruff format --check .
51+
# 本地直接 format(自动修复格式),CI 保留 --check 模式作为最终防线
52+
- id: ruff-format
53+
name: Ruff (format)
54+
language: system
55+
entry: uv run ruff format
56+
types_or: [python, pyi]
57+
require_serial: false

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
2. **Temp Management**: 临时产物(执行计划等)一律收敛至 `.temp/` 并及时清理;
4747
3. **Link Validity**: 确保所有引用的 URL 可访问且具备明确的上下文价值;
4848
4. **Git Commit**: 在需要提交变更到 Git 时,一律使用 Shell 调用 Claude Code 的自定义 Slash Command: `/commit` 进行 git commit 操作(若环境中未安装 Claude Code,则直接读取 `~/.claude/commands/commit.md`,按照其中的规则进行 git commit 操作)。不要执行 Rebase。
49+
5. **Pre-commit Hooks**: 克隆仓库后执行 `uv run pre-commit install` 激活本地 Git hooks,使 Ruff lint(含 auto-fix)、Ruff format 及通用代码卫生检查在每次 commit 前自动运行。若 hooks 自动修复了问题,提交会被中断,执行 `git add -p` 审阅修复内容后重新提交即可。
4950
- **Package Management Standardization (包管理规范)**:
5051
1. **Python**: 严禁使用 pip/poetry,**必须**统一使用 `uv` 进行包管理与脚本执行(如 `uv run`);
5152
2. **JavaScript/TypeScript**: 严禁使用 npm/yarn,**必须**统一使用 `pnpm` 进行包管理与脚本执行。

‎CHANGELOG.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
## [v0.1.1](https://github.com/ThreeFish-AI/coding-proxy/releases/tag/v0.1.1) — 2026-04-05
7272

7373
> [!IMPORTANT]
74-
>
75-
> **🎉 coding-proxy MVP 惊艳登场!**
76-
>
74+
>
75+
> **🎉 coding-proxy MVP 惊艳登场!**
76+
>
7777
> 仅需配置一行环境变量,立刻为你的 Claude Code 接入“永不宕机”的多源智能引擎。主供应商打盹?毫秒级自动无缝切换备用通道,全天候护航你的编码心流,向打断大声说不!
7878
7979
### ✨ 核心亮点

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ graph RL
118118
119119
subgraph CodingProxy["⚡ coding-proxy"]
120120
direction RL
121-
121+
122122
Router["RequestRouter<br/><code>routing/router.py</code>"]:::router
123123
124124
Router -->NTier
@@ -151,7 +151,7 @@ graph RL
151151
Tier2 -. "🆘 Safety Net Downgrade" .-> TierN
152152
end
153153
154-
end
154+
end
155155
156156
Client -->|"POST /v1/messages"| CodingProxy
157157
```

‎docs/zh-CN/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ graph RL
118118
119119
subgraph CodingProxy["⚡ coding-proxy"]
120120
direction RL
121-
121+
122122
Router["RequestRouter<br/><code>routing/router.py</code>"]:::router
123123
124124
Router -->NTier
@@ -151,7 +151,7 @@ graph RL
151151
Tier2 -. "🆘 Safety Net Downgrade" .-> TierN
152152
end
153153
154-
end
154+
end
155155
156156
Client -->|"POST /v1/messages"| CodingProxy
157157
```

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dev = [
4747
"pytest-asyncio>=1.3",
4848
"pytest-cov>=6.0",
4949
"ruff>=0.9.0",
50+
"pre-commit>=4.0",
5051
]
5152

5253
# ── Ruff: Linter & Formatter(替代 flake8 + isort + Black + pyupgrade 等 6+ 工具) ──

‎uv.lock‎

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)