From 4319afc08f04cbf6d9e0eb28f6426cb5304815ed Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Wed, 1 Apr 2026 01:44:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=20git=20pre-commit?= =?UTF-8?q?=20hook=20=E2=80=94=20=E6=8F=90=E4=BA=A4=E5=89=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BF=90=E8=A1=8C=20Biome=20=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 .githooks/ 目录 + core.hooksPath 方案,零依赖。 prepare script 确保 bun install 后自动激活。 Co-Authored-By: Claude Opus 4.6 --- .githooks/pre-commit | 22 ++++++++++++++++++++++ TODO.md | 2 +- package.json | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..b4d3b69 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,22 @@ +#!/bin/sh +# pre-commit hook: 对暂存的文件运行 Biome 检查 +# 仅检查 src/ 下的 .ts/.tsx/.js/.jsx 文件 + +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^src/.*\.(ts|tsx|js|jsx)$') + +if [ -z "$STAGED_FILES" ]; then + exit 0 +fi + +echo "Running Biome check on staged files..." + +# 使用 biome check 对暂存文件进行检查(仅 lint,不自动修复) +echo "$STAGED_FILES" | xargs bunx biome check --no-errors-on-unmatched + +if [ $? -ne 0 ]; then + echo "" + echo "Biome check failed. Fix errors or use --no-verify to bypass." + exit 1 +fi + +exit 0 diff --git a/TODO.md b/TODO.md index 65f1621..356b94a 100644 --- a/TODO.md +++ b/TODO.md @@ -19,4 +19,4 @@ - [x] 代码格式化与校验 - [ ] 冗余代码检查 -- [ ] git hook 的配置 +- [x] git hook 的配置 diff --git a/package.json b/package.json index 642ecfa..1c01bda 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "prepublishOnly": "bun run build", "lint": "biome check src/", "lint:fix": "biome check --fix src/", - "format": "biome format --write src/" + "format": "biome format --write src/", + "prepare": "git config core.hooksPath .githooks" }, "dependencies": { "@alcalzone/ansi-tokenize": "^0.3.0",