diff --git a/.config/hooks/pre-push b/.config/hooks/pre-push index 6fdbc64cd..bd5a0390c 100755 --- a/.config/hooks/pre-push +++ b/.config/hooks/pre-push @@ -113,6 +113,31 @@ else echo "pre-push: skipping Python lint (ruff not found — install with: pip install 'ruff>=0.9')" fi +# --- JSON syntax validation --- +if git rev-parse --verify "$REMOTE_REF" >/dev/null 2>&1; then + JSON_FILES=$(git diff --name-only "$REMOTE_REF"..HEAD -- '*.json' 2>/dev/null || true) +else + JSON_FILES=$(git ls-files '*.json') +fi +if [ -n "$JSON_FILES" ]; then + echo "pre-push: checking JSON syntax..." + JSON_FAIL=0 + while IFS= read -r f; do + if [ -f "$REPO_ROOT/$f" ] && ! python3 -m json.tool "$REPO_ROOT/$f" >/dev/null 2>&1; then + echo " FAIL: $f" + JSON_FAIL=$((JSON_FAIL + 1)) + fi + done <<< "$JSON_FILES" + if [ "$JSON_FAIL" -gt 0 ]; then + echo "pre-push: FAIL — $JSON_FAIL JSON file(s) have syntax errors" + ERRORS=$((ERRORS + 1)) + else + echo "pre-push: JSON — OK ($(echo "$JSON_FILES" | wc -l) file(s))" + fi +else + echo "pre-push: no JSON changes — skipping" +fi + if [ "$ERRORS" -gt 0 ]; then echo "" echo "pre-push: $ERRORS check(s) failed. Push aborted."