Something went wrong. Try again.
Custom Biome lint rules written as GritQL plugins
Something went wrong. Try again.
6.0 kB · 186 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187#!/usr/bin/env bashset -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"BIOME="${ROOT}/node_modules/.bin/biome"FAILED=0PASSED_COUNT=0FAILED_COUNT=0SHOW_ALL=0
usage() { cat <<EOFusage: scripts/test.sh [--all|--verbose|-v]
By default, only failed calls and the summary are printed.Use --all, --verbose, or -v to print every call.EOF}
for arg in "$@"; do case "$arg" in --all | --verbose | -v) SHOW_ALL=1 ;; -h | --help) usage exit 0 ;; *) echo "error: unknown argument: $arg" usage exit 1 ;; esacdone
log_all() { if [ "$SHOW_ALL" -eq 1 ]; then echo "$@" fi}
record_pass() { PASSED_COUNT=$((PASSED_COUNT + 1)) log_all "$@"}
record_fail() { FAILED=1 FAILED_COUNT=$((FAILED_COUNT + 1)) echo "$@"}
if [ ! -x "$BIOME" ]; then echo "error: biome not found. run 'npm install' first." exit 1fi
# test_fail <fixture> <expected_message># Runs biome on a fixture file and asserts the output contains the expected message.test_fail() { local fixture="$1" local expected="$2" local name name="$(basename "$fixture")"
output=$(cd "$ROOT" && "$BIOME" lint "$fixture" 2>&1 || true)
if echo "$output" | grep -qF "$expected"; then record_pass " pass: $name (error detected)" if [ "$SHOW_ALL" -eq 1 ]; then echo " output:" echo "${output//$'\n'/$'\n' }" fi else record_fail " FAIL: $name -- expected message not found: $expected" echo " output:" echo "${output//$'\n'/$'\n' }" fi}
# test_pass <fixture># Runs biome on a fixture file and asserts no errors are reported.test_pass() { local fixture="$1" local name name="$(basename "$fixture")"
set +e output=$(cd "$ROOT" && "$BIOME" lint "$fixture" 2>&1) status=$? set -e
if [ "$status" -eq 0 ]; then record_pass " pass: $name (no errors)" if [ "$SHOW_ALL" -eq 1 ]; then echo " output:" echo "${output//$'\n'/$'\n' }" fi else record_fail " FAIL: $name -- expected no errors but got:" echo "${output//$'\n'/$'\n' }" fi}
log_all "--- no-inline-imports ---"test_fail "tests/fail/no-inline-imports.tsx" "All imports should be at the top of the file"test_pass "tests/pass/no-inline-imports.tsx"
log_all "--- no-interpolated-classname ---"test_fail "tests/fail/no-interpolated-classname.tsx" "Use cn() instead of template literal in className"test_pass "tests/pass/no-interpolated-classname.tsx"
log_all "--- phosphor-icon-suffix ---"test_fail "tests/fail/phosphor-icon-suffix.tsx" "Phosphor icon imports require Icon suffix"test_pass "tests/pass/phosphor-icon-suffix.tsx"
log_all "--- no-js-import-extension ---"test_fail "tests/fail/no-js-import-extension.tsx" "Remove the .js extension"test_pass "tests/pass/no-js-import-extension.tsx"
log_all "--- no-ts-import-extension ---"test_fail "tests/fail/no-ts-import-extension.tsx" "Remove the .ts extension"test_pass "tests/pass/no-ts-import-extension.tsx"
log_all "--- no-emojis ---"test_fail "tests/fail/no-emojis.tsx" "Emojis are not allowed in code"test_pass "tests/pass/no-emojis.tsx"
log_all "--- no-inner-types ---"test_fail "tests/fail/no-inner-types.tsx" "Do not declare TypeScript types inside functions"test_pass "tests/pass/no-inner-types.tsx"
log_all "--- pi-no-node-exec ---"test_fail "tests/fail/pi-no-node-exec.tsx" "Do not use child_process directly"test_pass "tests/pass/pi-no-node-exec.tsx"
log_all "--- no-buried-await ---"test_fail "tests/fail/no-buried-await.ts" "Do not bury await inside"test_pass "tests/pass/no-buried-await.ts"
log_all "--- no-empty-catch ---"test_fail "tests/fail/no-empty-catch.tsx" "Empty catch blocks are not allowed"test_pass "tests/pass/no-empty-catch.tsx"
log_all "--- no-homedir ---"test_fail "tests/fail/no-homedir.ts" "Do not use os.homedir()"test_pass "tests/pass/no-homedir.ts"
log_all "--- no-is-record ---"test_fail "tests/fail/no-is-record.ts" "Do not create isRecord() helpers"test_pass "tests/pass/no-is-record.ts"
log_all "--- no-unimported-text ---"test_fail "tests/fail/no-unimported-text.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-combined-type.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-default-type.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-inline-type.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-local.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-local-type.ts" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-member.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-namespace-type.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-parameter.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-renamed.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-destructured.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-shadowed.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-type.tsx" "Text must come from a runtime import"test_fail "tests/fail/no-unimported-text-type-reference.ts" "Text must come from a runtime import"test_pass "tests/pass/no-unimported-text.tsx"test_pass "tests/pass/no-unimported-text-alias.tsx"test_pass "tests/pass/no-unimported-text-combined.tsx"test_pass "tests/pass/no-unimported-text-combined-default.tsx"test_pass "tests/pass/no-unimported-text-default.tsx"test_pass "tests/pass/no-unimported-text-earendil-pi-tui.ts"test_pass "tests/pass/no-unimported-text-namespace.tsx"test_pass "tests/pass/no-unimported-text-pi-tui.ts"
echo ""echo "Summary: $PASSED_COUNT passed, $FAILED_COUNT failed"
if [ "$FAILED" -eq 1 ]; then echo "SOME TESTS FAILED" exit 1else echo "ALL TESTS PASSED"fi