Skip to content
Toolkit

0157 — A dead rule is found by a census, not by standing next to it

  • Status: accepted, 2026-09-01
  • Deciders: Renaissance workstream 002, LEDGER drain (rows 60 and 89)
  • Applies: ADR-0021 (emitter counts before deletion), ADR-0037 (the counting method, offered there as a candidate), ADR-0141 (the gate-over-a-ledger shape, settings-reach's S1/S2)

Context

Every conversion on this workstream counts a class's emitters before deleting its rules (ADR-0021), and three sweeps of the same classes returned three different sets of numbers because each rebuilt the counter from memory — one counted *.test.tsx, one matched template literals whole so an inner 'ink' kept its quotes and never matched ink (both caught only because ADR-0037's run predicted all 21 deltas by hand first). LEDGER rows 60 and 89 held the finding open: the method exists, validated once, committed nowhere, wired into nothing.

Meanwhile every piece of dead app CSS on record was found by standing next to it. .framed-head, .topbar-search, .panel-w-md, .card-footer, .stat-card, .sidebar-compose — each noticed because a conversion happened to grep the neighbourhood, each swept only after a LEDGER row aged.

Decision

The counter is committed once as scripts/lib/emitter-census.mjs, with two callers that cannot drift from each other: node scripts/count-emitters.mjs <class>… for conversion-time counts, and check:emitters in verify.

An emitter is a class-writing position, counted once per position:

  • a className= value — quoted string, or brace expression matched by balancing braces — with every string literal inside tokenised on whitespace and quote characters (ADR-0037's method, verbatim);
  • a classList.add()/classList.toggle() argument list — the app writes classes the DOM way too (WidgetLibrary's dragging), and a counter that reads only JSX calls a live rule dead. remove() emits nothing;
  • a class="…" value in apps/web/index.html and in preview pages that link the app sheets — a preview card can be a rule's last emitter (.chip-count, ADR-0036's trap).

The corpus is what the app renders: apps/web/src and studio/packages/react/src — the app mounts Studio's components, so patterns.css styling .lk-card is styling a class surfaces.jsx emits on every page, and a census that cannot see that calls the rule dead. Tests and stories are excluded (an assertion parsing className emits nothing), comments are blanked to same-length spaces with strings skipped, and a CSS selector is never an emitter — a selector reads the class, only markup writes it (LEDGER row 110).

The gate holds two rules, settings-reach's shape one substrate over:

  • EM1 — every class an app stylesheet defines is emitted somewhere in the corpus, or is a row in scripts/emitter-ledger.json. A rule styling nothing may exist; silently doing so may not.
  • EM2 — every row is still emitterless and still defined. A row whose class gained an emitter, or whose rules left every sheet, is deleted in the commit that did it, so the count only falls.

The first run

91 of 479 defined classes have no emitter anywhere, seeded as the ledger. The largest finding is coherent, not scattered: home.css's entire explore-section mock family — mini-vc*, mini-site*, mini-og*, ex*, art-*, w1/w2/m/s2, ~35 classes of vCard/site/OG-card miniatures the home-canvas port shipped and the ported page never drew. Beside it: base.css's unused type scale (headline-*, caption*, body-lg) and animation helpers (anim-fade, stagger-1..6); components.css's outlived drawer, empty-state and progress chrome; and single findings with their own notes in the ledger — .tabbar styles a wrapper neither consuming page emits, and .control.is-invalid promises an invalid paint no form has ever set. Draining is one-surface-per-PR slices, house rules deciding archive-vs-delete per slice; this commit moves no rendered byte.

Bounds, stated

The census is lexical, not an AST. A class composed at runtime (is-${state}) counts only through its literal parts; a string assigned to a variable before reaching className is invisible. That bound is why EM1 takes a ledger row rather than deleting anything itself, and why a future library-injected class gets a row whose note says so rather than an exemption mechanism nothing needs yet.

ex__title aside, the census keys on class names, not (name, sheet) pairs: a class emitted anywhere is alive in every sheet that styles it. Good enough until a counterexample exists; the row records which sheets define it either way.

Verification

Watched failing five ways before being trusted: a new emitterless class with no row (EM1); the same class named in a comment only — still EM1, proving blanking; a row for an emitted class, a row for an undefined class, and a duplicated row (all EM2). Validated against known numbers: .control counts exactly SESSION's nine hand-rolled app emitters plus the preview card; .chip-count counts its one preview emitter; .dragging counts through classList.add; .lk-card counts through surfaces.jsx.

Source: docs/decisions/0157-a-dead-rule-is-found-by-a-census-not-by-standing-next-to-it.md

Library