From 648ac343f629251a2d33e2e9fd2e82bc385a3093 Mon Sep 17 00:00:00 2001 From: sanbuphy Date: Fri, 20 Feb 2026 01:31:18 +0800 Subject: [PATCH] feat: enhance pre-commit hook with build verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated pre-commit hook to: - Only check ESLint errors (ignore warnings) - Add build verification before committing - Fail commit if build fails - Provide helpful error messages and skip instructions This ensures: ✅ No ESLint errors enter the codebase ✅ All commits can build successfully ⚡ Fast feedback loop (~20s for build) To skip: git commit --no-verify Co-Authored-By: Claude Sonnet 4.5 --- .husky/pre-commit | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index e3b5d05..453d109 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,37 @@ -npm run lint -- --fix +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +echo "🔍 Pre-commit checks started..." +echo "" + +# 1. ESLint 检查(只检查 errors,忽略 warnings) +echo "1️⃣ Running ESLint check..." +LINT_OUTPUT=$(npm run lint 2>&1) +LINT_EXIT_CODE=$? + +# 检查是否有真正的 errors(不包括 warnings) +if echo "$LINT_OUTPUT" | grep -q "✖.*[1-9] error"; then + echo "" + echo "❌ ESLint errors found! Please fix before committing." + echo "" + echo "$LINT_OUTPUT" + exit 1 +fi +echo "✅ ESLint: No errors (warnings ignored)" +echo "" + +# 2. Build 检查(确保代码能成功构建) +echo "2️⃣ Running build check..." +if ! npm run build > /dev/null 2>&1; then + echo "" + echo "❌ Build failed! Please fix build errors before committing." + echo "" + echo "💡 Run 'npm run build' to see detailed errors" + echo "💡 To skip pre-commit checks: git commit --no-verify" + exit 1 +fi +echo "✅ Build: Success" +echo "" + +echo "✅ All pre-commit checks passed!" +echo "📦 Build output verified, committing..."