mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-01 09:37:11 +09:00
The guard only ran inside a backend pytest shard, so a citation in SCSS or JSX surfaced minutes after the push. The pre-commit hook now runs the same test file in --staged mode on every staged app file, reusing its patterns and PENDING allowlist so the two cannot drift.
54 lines
2.0 KiB
Bash
Executable File
54 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# ServerKit pre-commit hook — blocks internal plan citations in any staged app
|
|
# file, then lints staged frontend JS/JSX and blocks the commit on ESLint
|
|
# ERRORS only (warnings are allowed). The lint half exits early for commits
|
|
# that touch no frontend JS/JSX (backend, SCSS, docs). Enable once per clone with:
|
|
#
|
|
# git config core.hooksPath .githooks
|
|
#
|
|
# (Or run frontend/setup-hooks.sh.)
|
|
|
|
# Plan-citation guard: same patterns and allowlist as
|
|
# backend/tests/test_no_plan_references.py, run on the staged blobs of every
|
|
# file type (SCSS and Python included) so CI never has to catch it.
|
|
# First interpreter that actually runs (Windows ships a python3 stub that
|
|
# only opens the Store); none found means the CI test still covers it.
|
|
py=""
|
|
for candidate in python3 python; do
|
|
if "$candidate" -c 'import sys; sys.exit(sys.version_info < (3, 8))' 2>/dev/null; then
|
|
py=$candidate
|
|
break
|
|
fi
|
|
done
|
|
if [ -n "$py" ]; then
|
|
if ! "$py" backend/tests/test_no_plan_references.py --staged; then
|
|
echo ""
|
|
echo "✖ Commit blocked: remove the plan reference(s) above."
|
|
echo " To bypass for an emergency commit: git commit --no-verify"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '^frontend/src/.*\.(js|jsx)$' || true)
|
|
[ -z "$files" ] && exit 0
|
|
|
|
cd frontend || exit 0
|
|
# Skip silently if deps aren't installed yet (don't fetch/block).
|
|
[ -d node_modules ] || exit 0
|
|
|
|
rel=$(echo "$files" | sed 's#^frontend/##')
|
|
# Keep each invocation below Windows' command-line limit on broad migrations.
|
|
# xargs still returns a failure if any batch fails.
|
|
echo "$rel" | xargs -n 20 npx eslint
|
|
status=$?
|
|
|
|
# Theme-token guard (plan 60): whitelist/validators/alias expansion/seed themes.
|
|
node scripts/check-theme-tokens.mjs || status=1
|
|
|
|
if [ "$status" -ne 0 ]; then
|
|
echo ""
|
|
echo "✖ Commit blocked: fix the ESLint/theme-token error(s) above (warnings are allowed)."
|
|
echo " To bypass for an emergency commit: git commit --no-verify"
|
|
fi
|
|
exit $status
|