diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..f6f7d02 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,34 @@ +#!/bin/sh +# 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)$') + +if [ -z "$STAGED" ]; then + exit 0 +fi + +echo "Running Biome fix on staged files..." + +# 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=$? + +# 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..4e73a23 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,34 @@ +#!/bin/sh +# 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..." +"$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..." +"$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",