#!/usr/bin/env bash # Parse-check every script in the project. ~5s, so run it after every edit -- # it is the fastest signal that a change is syntactically and type-wise sound. # # Two stages, both necessary: # 1. --import refreshes .godot/global_script_class_cache.cfg. Without it, a # newly added `class_name` is invisible and every use of it reports # "Identifier not declared", which looks like a real error but is not. # 2. check.tscn loads every script so the engine prints real parse errors. # Set SKIP_IMPORT=1 to skip stage 1 when you have not added a class_name. set -uo pipefail cd "$(dirname "$0")/.." GODOT="${GODOT:-godot}" if [[ "${SKIP_IMPORT:-0}" != "1" ]]; then "$GODOT" --headless --path . --import >/dev/null 2>&1 fi out=$("$GODOT" --headless --path . res://tools/check.tscn 2>&1) if ! grep -q "CHECK_COMPLETE" <<<"$out"; then echo "check.tscn did not finish -- engine output follows:" >&2 echo "$out" >&2 exit 2 fi problems=$(grep -E "Parse Error|Failed to load script|does not inherit|SCRIPT ERROR" <<<"$out" || true) if [[ -n "$problems" ]]; then grep -E -A2 "Parse Error|Failed to load script|does not inherit|SCRIPT ERROR" <<<"$out" echo echo "FAIL: $(wc -l <<<"$problems") problem line(s)" >&2 exit 1 fi grep -o 'CHECK_COMPLETE scripts=[0-9]*' <<<"$out" | sed 's/CHECK_COMPLETE /clean, /'