31 lines
1.9 KiB
Bash
31 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
# Lint (bash tools/lint.sh):
|
|
# 1. GLOBALS: unknown globals (luau-analyze), a local used before its declaration compiles fine but reads a nil
|
|
# global at runtime. Roblox globals are allowed (the library runs in Roblox, luau and LuaJIT). Other type errors
|
|
# are counted and printed with LINT_TYPES=1, but do not fail the lint (absorbed code predates --!strict).
|
|
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT:
|
|
# tools/lint_rules.py (its header lists the rules; docs/STYLE.md explains them).
|
|
# 3. The generated registry / docs/FORMATS.md are up to date (tools/gen_registry.py --check), and tools/build.py's
|
|
# token passes pass their self-test.
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
ANALYZE=${ANALYZE:-$(command -v luau-analyze || nix shell nixpkgs#luau -c sh -c 'command -v luau-analyze')}
|
|
ALLOW="game|script|workspace|Instance|Enum|Vector3|Vector2|Color3|CFrame|task|typeof|warn|tick|time|buffer|vector|bit32|utf8|debug|shared|plugin|SharedTable|Random"
|
|
fail=0
|
|
mapfile -t files < <(find src tests tools -name '*.luau' -not -path 'tests/gen/*' | sort)
|
|
report=$("$ANALYZE" "${files[@]}" 2>&1)
|
|
bad=$(echo "$report" | grep "Unknown global" | grep -vE "'($ALLOW)'")
|
|
if [ -n "$bad" ]; then
|
|
echo "$bad"
|
|
echo "lint: unknown globals (a local used before it is declared?)"
|
|
fail=1
|
|
fi
|
|
ntype=$(echo "$report" | grep -c "Error:")
|
|
[ -n "$LINT_TYPES" ] && echo "$report" | grep -v "Unknown global"
|
|
python3 -I tools/lint_rules.py || { echo "lint: structure rules failed (see tools/lint_rules.py)"; fail=1; }
|
|
python3 -I tools/gen_registry.py --check > /dev/null || { python3 -I tools/gen_registry.py --check; fail=1; }
|
|
python3 -I tools/build.py --test > /dev/null || { echo "lint: tools/build.py --test failed"; fail=1; }
|
|
if [ $fail -eq 0 ]; then
|
|
echo "lint passed (globals, header, require, native, layers, deps, contract, registry; $ntype type diagnostics: LINT_TYPES=1 shows them)"
|
|
fi
|
|
exit $fail
|