#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" BIOME="${ROOT}/node_modules/.bin/biome" FAILED=0 PASSED_COUNT=0 FAILED_COUNT=0 SHOW_ALL=0 usage() { cat < # 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 # 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 1 else echo "ALL TESTS PASSED" fi