From db3daecfaffa03769607fdd789a08f88713c5669 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Mon, 6 Apr 2026 16:00:29 +0200 Subject: [PATCH] chore(config): add JSON syntax validation to pre-push hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validates changed JSON files using python3 -m json.tool (zero dependencies). Same diff-based scoping as existing checks — only files changed vs remote are validated. Blocks push on syntax errors. Co-Authored-By: Claude Opus 4.6 (1M context) --- .config/hooks/pre-push | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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."