audit(ui): CSS class drift audit script (#2502)#2507
Merged
alexey-pelykh merged 1 commit intomainfrom Apr 23, 2026
Merged
Conversation
…nces with no CSS definition (#2502) Scans ui/src TS/TSX for static class="..." tokens (and literal-only class=\${"..."} / class=\${\`template\`} forms) and diffs against the set of classes defined in CSS reachable from ui/src/styles.css via @import. Orphaned references are clustered by the commit that removed the defining rule, making fork-sync drift visible in one pass. The script is a one-shot triage helper, not a CI gate (see #2503 for the build-time gate that depends on this audit clearing). Runs CI-friendly: no prompts, exit 0 when clean, exit 1 on findings, exit 2 on fatal. Output: .tmp/audit-css-drift.md (gitignored via .tmp/). Current state on audit/2502-css-class-drift @ origin/main: 36 orphans across 3 drift clusters (v2026.3.22 config-sidebar family, v2026.3.13-1 nav+theme-toggle residue after #2501, btn-sm rename) plus 9 unresolved (no removing-commit in CSS history — missing-CSS candidates, not drift). Follow-up fix(ui) issues filed per cluster. Design notes: - Reference extraction walks Lit template strings with brace/string awareness so class="btn \${cond ? \"active\" : \"\"}" doesn't confuse the parser with the inner quote. - Interpolation content is scope-out per #2502 — static tokens AROUND interpolations ARE captured, content INSIDE is not (avoids FP flood from enum-discriminant and i18n-key string literals). - CSS selector extraction handles compound selectors (.btn.primary), BEM (.block__elem--mod), pseudo-class suffixes, and nested @media blocks. Allows a preceding word character before the dot so .btn.primary yields both classes. - Cluster attribution uses git log -S .className pickaxe, then filters per-commit diffs with a selector-boundary regex so .nav isn't conflated with .nav-section on substring matches.
7 tasks
alexey-pelykh
added a commit
that referenced
this pull request
Apr 23, 2026
… 3 of #2502 CSS class drift audit (#2510) Upstream `21ac4b9a8a` (style(ui) clarity pass, openclaw#53272) migrated `.btn-sm` to `.btn--sm` under the BEM modifier convention. The fork's `ui/src/ui/views/channels.nostr.ts:131` still referenced the pre-rename `btn-sm` token; the CSS rule `.btn--sm` is defined at `ui/src/styles/components.css:625`. The stale reference was surfaced as cluster 3 (1 orphan) by the CSS class drift audit introduced in #2507. Post-fix audit: orphans 36 → 35, clusters 3 → 2, cluster 3 eliminated entirely. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
alexey-pelykh
added a commit
that referenced
this pull request
Apr 23, 2026
… 3 of #2502 CSS class drift audit (#2510) (#2512) Upstream `21ac4b9a8a` (style(ui) clarity pass, openclaw#53272) migrated `.btn-sm` to `.btn--sm` under the BEM modifier convention. The fork's `ui/src/ui/views/channels.nostr.ts:131` still referenced the pre-rename `btn-sm` token; the CSS rule `.btn--sm` is defined at `ui/src/styles/components.css:625`. The stale reference was surfaced as cluster 3 (1 orphan) by the CSS class drift audit introduced in #2507. Post-fix audit: orphans 36 → 35, clusters 3 → 2, cluster 3 eliminated entirely. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
scripts/audit-css-class-drift.mjs— a one-shot triage helper that surfaces fork-sideclass="..."tokens inui/src/**/*.{ts,tsx}that have no matching rule anywhere in theui/src/styles.cssimport graph.Addresses #2502. The #2501 fix (nav-section + topbar vocabulary after v2026.3.13-1 sync) was the first visible symptom; this audit generalizes the detection so future drift surfaces in one pass instead of reactively, component by component, as users notice broken styling.
What this PR does
.tmp/audit-css-drift.md(already gitignored via.tmp/).Current state on this branch
Running the script against
origin/main:0667aa5596(v2026.3.22 sync) — 21 orphans — full.config-sidebar*/.config-search__tag-*/.config-nav*/.config-subnav*family gone; upstream moved to.config-top-tabs04a7853f0f(v2026.3.13-1 sync) — 5 orphans — residue after fix(ui): restore nav-section/topbar class names after v2026.3.13-1 sync — paired call-site update missed #2501:.nav(→.sidebar),.nav--collapsed(→.sidebar--collapsed),.theme-toggle*(→.theme-orb*)21ac4b9a8a(style(ui) clarity pass) — 1 orphan —.btn-sm(→.btn--sm).cron-run-entry__main,.cron-run-entry__title,.nav-item--external,.nav-section--links), fork-side classes with no rule (.nostr-profile-form,.form-field,.monospace,.debug-event-log), and one dynamic-construction scope-out (.language-prefix fromclass="language-${lang}").Design decisions
class="btn ${cond ? \"active\" : \"\"}"doesn't confuse the parser with the inner quote (naiveclass="[^"]*"regex breaks here).${...}ARE captured; content INSIDE is not. This avoids the false-positive flood from string literals used as enum discriminants, i18n keys, or comparison values..btn.primary→ bothbtnandprimary), BEM, pseudo-classes,:not(...), and nested@mediablocks.git log -S .classNamewith a selector-boundary filter on per-commit diffs so.navisn't conflated with.nav-sectionon substring pickaxe hits.Known limitations
Documented in-script and in the report. The big ones:
${variable},classList.add(...),classMap(...)) is out of scope.ui/src/styles.cssimport graph is not analyzed.Test plan
node scripts/audit-css-class-drift.mjsruns to completion, writes.tmp/audit-css-drift.md, exits 1 with 36 orphans.tmp/(gitignored) — not accidentally committedpnpm format,pnpm lint,pnpm tsgoall cleangit show <sha>diffs.btn.primaryyields bothbtnandprimary)class="btn ${cond ? \"active\" : \"\"}"correctlyFollow-ups
fix(ui)issue filed per cluster with the renames table