chore(ui): move existing inline null/empty and typeof checks to the guards

Chiusa
#937 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@bitcoinbrisbane ci sta già lavorando.

Dal 1/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

refactor tech debt UI

Why

UI Architecture Commandment 8 (CLAUDE.md) says null, empty and length checks go through src/utils/guards.ts. Since #933, the Guards CI job (yarn check:guards) enforces this, but only on lines a PR adds. Older code was never moved over, so it doesn't match the rule. Any PR that touches those files either inherits the old checks or ends up mixing unrelated guard fixes into its diff (as #936 did; now closed).

The last adoption pass was #449 (#451, #453, #459, #473).

What's left on main (9420ff5)

Counted with the same rules check:guards uses (scripts/guards/rules.ts), over whole files. Comments and // guards-ok lines are skipped.

136 hand-written null/empty/length checks in 63 files

Use instead Count
hasValue(x) 64
isNullish(x) 48
isEmpty(x) / isBlank(x) 12
hasElements(x) / hasContent(x) 12

Densest files: pages/TableAdminPage.tsx (15), bus/GameMessageBus.ts (8), components/bridge/StuckPaymentsPanel.tsx (8), pages/Dashboard.tsx (6), submit/ActionSubmitController.ts (5), utils/turnClock.ts (5).

30 typeof checks in 19 files, mostly narrowing an unknown reply field, e.g.

const msg = typeof raw?.message === "string" ? raw.message : response.statusText; // hooks/game/useFetchSngClaimSignature.ts
rawLog: typeof rawLog === "string" ? rawLog : "",                               // submit/txVerdict.ts
if (typeof err === "object" && err !== null) {                                  // apis/HTTPClient.ts

There are no guards for these yet. Most are in constants/currency.ts, submit/txVerdict.ts, components/explorer/ClickableAddress.tsx, audio/actionSoundPlayer.ts and apis/HTTPClient.ts.

Scope

  1. Replace the 136 checks with the existing guards. Where null and undefined mean different things, keep the strict check and end the line with // guards-ok. Example: #919's ante rule, where null means "antes off" and undefined means "not set". isNullish would merge them.
  2. Add type guards for the typeof cases, with tests in guards.test.ts: isString, isNumber, isBoolean, and isRecord for "non-null object whose fields can be read". Then switch the 30 sites to them and list the new guards in Commandment 8.
  3. Teach check:guards the typeof pattern so new ones are flagged once the guards exist.

How

  • Its own PRs, split by directory (bus/ + submit/, hooks/, components/, pages/, utils/ + apis/), not folded into feature PRs.
  • No behaviour change. Each PR passes tsc -b, the full jest suite and check:guards.
  • No visible change, so no screenshots.
Lingua principale
TypeScript
Stelle
2
Fork
5
Merge medio
22h 3m
PR unite (30g)
103

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di block52/ui

Tutte le issue di block52/ui

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.