#!/usr/bin/env bash # PostToolUse hook (Edit/Write): quick syntax check on the file that was just changed. # No linter/formatter is configured for this project, so this only catches # JS syntax errors and invalid JSON. set -euo pipefail input=$(cat) file_path=$(echo "$input" | node -e " let d=''; process.stdin.on('data', c => d += c); process.stdin.on('end', () => { try { const j = JSON.parse(d); process.stdout.write(j.tool_input?.file_path || ''); } catch { process.stdout.write(''); } }); " <<< "$input") [ -z "$file_path" ] && exit 0 [ -f "$file_path" ] || exit 0 case "$file_path" in *.js) node --check "$file_path" ;; *.json) node -e "JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8'))" "$file_path" ;; *) exit 0 ;; esac