From c613b2e74a6115259f73895756c8e304c9e2659c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 13:52:15 +0000 Subject: [PATCH 1/3] chore: add pre-commit and pre-push git hooks for format and lint - .githooks/pre-commit: runs `biome check --write` on staged TS/JS/JSON/HTML files, re-stages them, and aborts if unfixable errors remain - .githooks/pre-push: runs `biome lint` + `tsc --noEmit` before any push, blocking pushes that introduce lint or type errors - package.json: adds `prepare` script so `npm install` auto-registers .githooks as the hooks path via `git config core.hooksPath` https://claude.ai/code/session_01D8L26tFHVcgikgcTpcqoJe --- .githooks/pre-commit | 28 ++++++++++++++++++++++++++++ .githooks/pre-push | 26 ++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 .githooks/pre-commit create mode 100755 .githooks/pre-push diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..cc59e27 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,28 @@ +#!/bin/sh +# Pre-commit hook: auto-format and lint staged files with Biome. +# Aborts the commit if unfixable lint errors remain after auto-fix. + +STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ts|js|json|html)$') + +if [ -z "$STAGED" ]; then + exit 0 +fi + +echo "Running Biome fix on staged files..." + +# Run biome fix on the staged files +echo "$STAGED" | xargs npx biome check --write --no-errors-on-unmatched + +STATUS=$? + +# Re-stage the files that were originally staged (biome may have modified them) +echo "$STAGED" | xargs git add + +if [ $STATUS -ne 0 ]; then + echo "" + echo "Biome reported errors that could not be auto-fixed." + echo "Please fix the issues above and try committing again." + exit 1 +fi + +exit 0 diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..009cadc --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,26 @@ +#!/bin/sh +# Pre-push hook: run full lint and type-check before pushing. +# Blocks the push if there are lint errors or type errors. + +echo "Running Biome lint check..." +npx biome lint . +LINT_STATUS=$? + +if [ $LINT_STATUS -ne 0 ]; then + echo "" + echo "Lint errors found. Run 'npm run fix' to auto-fix, then commit and push again." + exit 1 +fi + +echo "Running TypeScript type check..." +npx tsc --noEmit +TSC_STATUS=$? + +if [ $TSC_STATUS -ne 0 ]; then + echo "" + echo "TypeScript errors found. Fix the errors above before pushing." + exit 1 +fi + +echo "All checks passed." +exit 0 diff --git a/package.json b/package.json index 52d2654..974a6df 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "watch": "tsc --watch", "clean": "rm -rf dist", "generate-svg-icon": "tsx scripts/bouncingBallToSVG.ts", - "icons": "npm run generate-svg-icon && tsx scripts/generate-icons.ts" + "icons": "npm run generate-svg-icon && tsx scripts/generate-icons.ts", + "prepare": "git config core.hooksPath .githooks" }, "dependencies": { "@ffmpeg/core": "^0.12.10", From f0f0f6803d429b1f429a7170785fc1b6bb175245 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 13:52:41 +0000 Subject: [PATCH 2/3] fix: use local node_modules binaries in git hooks Replace npx biome/tsc calls with ./node_modules/.bin/ paths to avoid pulling down a stale global version during hook execution. https://claude.ai/code/session_01D8L26tFHVcgikgcTpcqoJe --- .githooks/pre-commit | 2 +- .githooks/pre-push | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index cc59e27..6dcc967 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -11,7 +11,7 @@ fi echo "Running Biome fix on staged files..." # Run biome fix on the staged files -echo "$STAGED" | xargs npx biome check --write --no-errors-on-unmatched +echo "$STAGED" | xargs ./node_modules/.bin/biome check --write --no-errors-on-unmatched STATUS=$? diff --git a/.githooks/pre-push b/.githooks/pre-push index 009cadc..bf63f50 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -3,7 +3,7 @@ # Blocks the push if there are lint errors or type errors. echo "Running Biome lint check..." -npx biome lint . +./node_modules/.bin/biome lint . LINT_STATUS=$? if [ $LINT_STATUS -ne 0 ]; then @@ -13,7 +13,7 @@ if [ $LINT_STATUS -ne 0 ]; then fi echo "Running TypeScript type check..." -npx tsc --noEmit +./node_modules/.bin/tsc --noEmit TSC_STATUS=$? if [ $TSC_STATUS -ne 0 ]; then From eb3f85cf66d51a2b68541af4f320092c92ae993b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 13:54:19 +0000 Subject: [PATCH 3/3] fix: add npm install guard and clear error message in git hooks If node_modules binaries are missing, hooks now print an actionable message and exit cleanly instead of a cryptic "not found" error. https://claude.ai/code/session_01D8L26tFHVcgikgcTpcqoJe --- .githooks/pre-commit | 12 +++++++++--- .githooks/pre-push | 12 ++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 6dcc967..f6f7d02 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,5 +1,5 @@ #!/bin/sh -# Pre-commit hook: auto-format and lint staged files with Biome. +# Pre-commit hook: auto-format and lint the project with Biome. # Aborts the commit if unfixable lint errors remain after auto-fix. STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ts|js|json|html)$') @@ -10,8 +10,14 @@ fi echo "Running Biome fix on staged files..." -# Run biome fix on the staged files -echo "$STAGED" | xargs ./node_modules/.bin/biome check --write --no-errors-on-unmatched +# Run biome fix on staged files only (using node_modules binary so npm scripts are not needed) +BIOME="./node_modules/.bin/biome" +if [ ! -x "$BIOME" ]; then + echo "Biome not found in node_modules. Run 'npm install' first." + exit 1 +fi + +echo "$STAGED" | xargs "$BIOME" check --write --no-errors-on-unmatched STATUS=$? diff --git a/.githooks/pre-push b/.githooks/pre-push index bf63f50..4e73a23 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -2,8 +2,16 @@ # Pre-push hook: run full lint and type-check before pushing. # Blocks the push if there are lint errors or type errors. +BIOME="./node_modules/.bin/biome" +TSC="./node_modules/.bin/tsc" + +if [ ! -x "$BIOME" ] || [ ! -x "$TSC" ]; then + echo "Required tools not found in node_modules. Run 'npm install' first." + exit 1 +fi + echo "Running Biome lint check..." -./node_modules/.bin/biome lint . +"$BIOME" lint . LINT_STATUS=$? if [ $LINT_STATUS -ne 0 ]; then @@ -13,7 +21,7 @@ if [ $LINT_STATUS -ne 0 ]; then fi echo "Running TypeScript type check..." -./node_modules/.bin/tsc --noEmit +"$TSC" --noEmit TSC_STATUS=$? if [ $TSC_STATUS -ne 0 ]; then