chore(config): add JSON syntax validation to pre-push hook
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user