panic-on-loading
panic(...) under a condition that reads a loading flag: a name made of loading, loaded, hydrated, pending, fetched or fetching (store.hydrated, isLoading, hydratedData), or a Loading / Idle / Pending variant. Checked: if (cond) panic(...), cond || panic(...), value ?? panic(...) and cond ? panic(...) : x. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: panic is for invariants nothing can handle, like a table with a name listed twice. "Not loaded yet" is a state every page goes through: a page that reads the store before its first answer lands crashes instead of showing a wait. Return an Option, or keep the state in an AsyncState or an Enum the caller shows. Guide: Errors.
✕ Rejectedpanic-on-loading
ts
import { panic } from "@evobug_com/safe-ts-std/result";
type Store = { readonly hydrated: boolean; readonly user?: { readonly name: string } };
export function userName(store: Store): string {
if (!store.hydrated) panic("store not hydrated");
return store.user?.name ?? "";
}✅ Accepted: the store keeps an AsyncState, and the caller shows each state
✓ Accepted0 diagnostics
ts
import type { AsyncState } from "@evobug_com/safe-ts-std/async-state";
import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";
type User = { readonly name: string };
type LoadError = Enum<{ Offline: {}; Status: { status: number } }>;
type Store = { readonly user: AsyncState<Option<User>, LoadError> };
export function userLine(store: Store): string {
return match(store.user, {
Ready: ({ value }) => value?.name ?? "Signed out",
Failed: () => "Couldn't load your account",
_: () => "Loading…",
});
}ts
import type { AsyncState } from "@evobug_com/safe-ts-std/async-state";
import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
import type { Option } from "@evobug_com/safe-ts-std/result";
type User = { readonly name: string };
type LoadError = Enum<{ Offline: {}; Status: { status: number } }>;
type Store = { readonly user: AsyncState<Option<User>, LoadError> };
export function userLine(store: Store): string {
{ const __ms1 = store.user; let __mv1: string; switch (__ms1?.tag) {
case "Ready": { const { value } = __ms1; __mv1 = value?.name ?? "Signed out"; break; }
case "Failed": { __mv1 = "Couldn't load your account"; break; }
default: { __mv1 = "Loading…"; break; } } return __mv1; }
}✅ Also accepted: an Option, where the store keeps a flag for now
✓ Accepted0 diagnostics
ts
import type { Option } from "@evobug_com/safe-ts-std/result";
type Store = { readonly hydrated: boolean; readonly user?: { readonly name: string } };
export function userName(store: Store): Option<string> {
return store.hydrated ? store.user?.name : undefined;
}A heuristic, by name. The checker can't tell where a value comes from at runtime, so it goes by the words in the condition. A panic whose condition names none of them isn't reported, even if the value came from a request; a flag named ready isn't one of the words, since it often guards a real invariant. A finding on a real invariant that happens to use one of the words is a false positive: say so in the condition's name, or turn the rule off.