claude-code/.githooks/pre-commit
claude-code-best 4319afc08f feat: 配置 git pre-commit hook — 提交前自动运行 Biome 检查
使用 .githooks/ 目录 + core.hooksPath 方案,零依赖。
prepare script 确保 bun install 后自动激活。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 01:44:55 +08:00

23 lines
587 B
Bash
Executable File
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.

#!/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