Repository navigation
Add Stylelint design-token enforcement for Svelte style blocks - #2663
Conversation
…#2589) ESLint cannot parse CSS inside Svelte `<style>` blocks, so the design-system drift that lives there — hardcoded colors, ad-hoc shadows, unauthorized motion — was invisible to the existing quality gate. Add Stylelint with postcss-html as the CSS-side gate, wired into quality:check/quality:fix. Three rules, from the design spec: - Color literals rejected on color-bearing properties; hsl(var(--token)) passes - box-shadow limited to the floating-surface value, none, or a token shadow - transition limited to the two approved cases; animation/@Keyframes rejected The codebase has 248 pre-existing violations across 44 files. Failing the mandatory gate on all of them would block every unrelated change until the remediation issues land, so scripts/check-design-tokens.ts compares against a recorded baseline and fails only on new drift. The baseline is a ratchet: it is also an error for it to contain entries that no longer occur, so fixing a file forces the baseline down and the count cannot silently grow back. Two rule-design details, both covered by tests: - The approved shadow is itself specified as a literal rgb() value, so it is exempted on box-shadow and matched whitespace-insensitively (the formatter wraps it across lines). - Focus rings use box-shadow but are not elevation, so token-built shadows are allowed rather than reported as false positives. customSyntax is applied per-extension rather than globally: applied globally it parses plain .css files as empty and silently skips every rule on them, which would have excluded noderef.css from the gate entirely. stylelint-declaration-strict-value was evaluated and rejected — ignoreFunctions true allows rgba(0,0,0,0.5), false rejects hsl(var(--token)) — so the color rule is a regex on the built-in declaration-property-value-disallowed-list. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Pragmatic Code Review — PR #2663 (issue #2589)Review Type: Initial Review Requirements Check
Findings🔴 F1 — Named CSS colors bypass the color rule entirely📁
This drift exists today in a file the issue names: The baseline has 30 entries for that file and zero mentioning Fix: add a named-color alternative to 🔴 F2 — A component-local custom property launders any raw color📁 Custom-property declarations ( A one-line, natural-looking bypass that reads as more idiomatic than the thing being blocked. Fix: flag raw literals in custom-property declarations outside 🔴 F3 —
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks requesting changes on your own PR). Blocking: F1 (named CSS colors bypass the color rule), F2 (custom-property declarations launder raw colors), F3 (stylelint-disable silently suppresses the gate). Full findings in the review comment above.
The gate let through the exact drift it targets. Each bypass below was reproduced against the real linter before and after the fix. F1 — named CSS colors were invisible to the color rule, which matched only hex and numeric color functions. `color: white` passed. This was not hypothetical: diagnostic-panel.svelte has three such declarations, in a file the remediation set targets, and the baseline recorded none of them. Adds the full CSS named-color list. F2 — a component-local custom property laundered any literal: `--brand: #ff00aa` then `color: var(--brand)` passed every rule and reads as more idiomatic than the thing being blocked. Adds a `/^--/` property key. F3 — `stylelint-disable` silently switched the gate off, against CLAUDE.md's no-suppression rule. reportDescriptionlessDisables alone was insufficient (it only flags a disable *without* a description, leaving a one-word bypass), so configurationComment is renamed: `stylelint-disable` is no longer a recognized directive and suppresses nothing. Also: - transition is matched per comma-segment, so the two approved transitions can be combined on one element rather than rejected for being combined (F4) - vendor-prefixed @Keyframes enumerated; this app ships on WebKit (F5) - the design-token check runs in scripts/test-gate.ts, so the gate is enforced by the push hook rather than by remembering to run it (F6) - readBaseline validates shape and reports the problem instead of throwing a stack trace from inside the diff (F7) - the baseline readme notes that a file rename needs a re-record (F9) Adding named colors initially introduced a false positive — `\b` matched inside identifiers, so `var(--white-overlay)` was rejected. Now bounded by `(?<![\w-])`/`(?![\w-])`, with tests for leading, trailing and embedded color words in token names. A gate that rejects correct code gets disabled. Not done: an --update guard (F8). The ratchet already surfaces silencing as a baseline-count increase in review, which is the signal that matters. Baseline re-recorded 248 -> 251. Design-token tests 30 -> 43, diff tests 8 -> 9. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review responseAll three blocking findings fixed, plus F4–F7 and F9. Baseline re-recorded: 248 → 251. Addressed
Two notes where I diverged from the suggestionF3 needed more than F1 introduced a false positive, caught by its own new test. Skipped
The three newly-caught violationsExactly the drift the review identified as invisible: A file remediation issue #2593 targets, previously unrecorded in the baseline. Verification
One self-inflicted issue worth recording: the F7 change initially failed |
…terals Adding named colors made the color rule scan raw declaration values, so a color word anywhere inside a URL path or a quoted string was reported as a literal — `url(/img/gold.png)` came back as `Raw color literal "url(/img/gold.png)"`, which also misdescribes the value. Two things made this worth fixing before the remediation issues start: - the `/^--/` key put every custom property under the color rule, so one holding a URL, a grid-area list or a content string was scanned for color words - a `data:` URI payload containing `stroke='white'` was flagged, and icon components are full of those — it would have fired on a correct icon change Boundary widened from `(?<![\w-])`/`(?![\w-])` to `(?<![\w\-./'"(])` and `(?![\w\-./'"])`. Detection is unweakened: `linear-gradient(white, black)` is still caught, verified explicitly because `(` is now in the lookbehind. `--anim-name: plum` still flags, deliberately. A bare word in a custom property is genuinely ambiguous between an animation name and a color, with nothing in the declaration to separate them, so flagging is the safer default. Also documents the override spelling in the config — it was previously discoverable only by reading stylelint's internals. Design tests 95 -> 103. Baseline holds at 251, so no genuine finding was lost. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Re-review follow-up: N1 fixedRe-review returned APPROVE with one non-blocking finding. Fixed it here rather than deferring, since it was a regression my own F1 fix introduced and it lands squarely where the remediation work is headed. N1 — color words inside URLs and quoted strings read as literals
Two things made this worth fixing now rather than following up:
Boundary widened from Now clean: Still caught — the wider boundary does not weaken detection: One deliberate non-fix
Nit also addressedThe override spelling is now documented in the config. It was previously discoverable only by reading stylelint's internals: Verification
|
Blocker (🔴): #2663 landed the design-token ratchet while this PR was in flight, wiring `quality:design-tokens` into quality:check/quality:fix. The gate failed with 21 net-new violations in diagnostic-panel.svelte. The mechanism is subtle: design-tokens-baseline.json keys entries on file/rule/text, and `text` embeds the literal verbatim. The baseline held `var(--color-text-muted, #888)`. Unwrapping that dead var() to a bare #888 — correct in itself, since --color-text-muted is defined nowhere — produced a different key, so the gate read the result as net-new drift. Fix the cause rather than the symptom: define six theme-invariant --console-* tokens in app.css and swap all 21 literals. HSL values round-trip to the exact original hex, so the console is pixel-identical. The panel keeps its deliberate dark-in-both-themes appearance while satisfying the token rule, and the rationale moves to app.css where the tokens are defined. This drives the baseline DOWN from 251 to 194 (-57): diagnostic-panel goes from 33 entries to 0. The baseline is re-recorded because violations were *fixed*, which the ratchet requires — not to absorb new ones, which it forbids. Important (🟡): remove `box-shadow` from .modal in invitations-inbox.svelte. DESIGN.md reserves elevation shadows for floating surfaces; modal panels get none, since the backdrop provides separation. This PR rewrote the .modal block two lines above and should have caught it. Comment corrections (🟡/🟢): the --*-light rationale said those tokens "flip" lightness, which is imprecise — the real disqualifier is that they have no paired --*-light-foreground token. The badge comment's "~2.5-2.8:1" also omitted that white-on---destructive clears AA in light at 4.57:1; the binding constraint is the 2.86:1 dark case. Both now state the measured figures, including .status.error sitting at 2.88:1 in light. Not addressed: the rgba(0,0,0,0.5) overlay scrim (1 remaining baseline entry). It is the identical value used by all four other modals, and no overlay token exists. Inventing a one-off here would break that consistency; it belongs to the modals remediation issue. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… tokens (closes #2592) (#2669) * Replace hardcoded status colors and phantom CSS variables with design tokens (closes #2592) diagnostic-panel.svelte and invitations-inbox.svelte bypassed the app.css semantic token system in two ways: hardcoded status hex literals, and references to a parallel CSS-variable vocabulary (--surface-1, --color-border, --text-primary, …) that is defined nowhere in the repo and so always resolved to its hardcoded fallback. The second problem was the more serious one. invitations-inbox.svelte is a user-facing modal whose fallbacks were all light-mode values, so it rendered as a white panel with dark text in dark mode regardless of theme — a real theming bug masked by token-shaped syntax that did nothing. Map status colors to --success/--destructive/--warning/--primary and chrome to --card/--foreground/--muted-foreground/--border, using hsl(var(--token)): the tokens are HSL triplets, so the rgb(var(--token) / alpha) form is wrong here. Ring/tint alpha follows the existing noderef.css:386 precedent. Contrast-check every mapping in both themes rather than matching by hue. Three pairings that looked correct fail WCAG AA: - State tags on --*-light: those tokens flip lightness between themes (pale in light, dark in dark), so no single foreground works — 2.22:1 and 3.41:1 in dark. Use a 0.15 tint of the solid token instead (12.7-17.7:1 both themes). - .status.success/.status.error badges: --success-foreground and --destructive-foreground are white in BOTH themes, landing at 2.55-2.83:1 on the solid mid-tone fills. Tint the background and use the state color as text. - .init-error-banner: white passes in light (4.57:1) but fails in dark (2.86:1) and the inverse foreground fails in light. Tinted for the same reason. diagnostic-panel.svelte stays a fixed dark console in both themes — it is a monospace developer tool, and mapping its surfaces to --background/--foreground would turn it white in light mode. Its surface greys remain explicit literals with the dead var() wrappers removed so the intent is honest, and a comment records why. Its status colors are tokenized and verified legible (4.17-7.68:1) against that surface. Known residual: .ok text is 2.83:1 in light mode. Neither --success nor --success-light is dark enough for body text on a white card; this is a gap in the token set rather than a mapping error, and warrants a separate issue. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Correct the repo-structure tree in CLAUDE.md The tree listed packages/design-system/, which does not exist, and omitted five packages that do: nodespace-types, proto, daemon, cli, and skill. dev-tools was described as "Development utilities" when it is specifically a Bun dev-proxy. Descriptions are taken from each package's own manifest (Cargo.toml `description` for the Rust crates, package.json for skill and dev-tools), and package order now follows the Cargo workspace members list. Also point at where the design system actually lives — packages/desktop-app/src/lib/design/ plus app.css for the color tokens — since that is what the missing design-system entry was gesturing at, and add the assets/ directory. Verified: every packages/ path referenced anywhere in CLAUDE.md now resolves. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Address review: add --console-* tokens, drop the modal shadow Blocker (🔴): #2663 landed the design-token ratchet while this PR was in flight, wiring `quality:design-tokens` into quality:check/quality:fix. The gate failed with 21 net-new violations in diagnostic-panel.svelte. The mechanism is subtle: design-tokens-baseline.json keys entries on file/rule/text, and `text` embeds the literal verbatim. The baseline held `var(--color-text-muted, #888)`. Unwrapping that dead var() to a bare #888 — correct in itself, since --color-text-muted is defined nowhere — produced a different key, so the gate read the result as net-new drift. Fix the cause rather than the symptom: define six theme-invariant --console-* tokens in app.css and swap all 21 literals. HSL values round-trip to the exact original hex, so the console is pixel-identical. The panel keeps its deliberate dark-in-both-themes appearance while satisfying the token rule, and the rationale moves to app.css where the tokens are defined. This drives the baseline DOWN from 251 to 194 (-57): diagnostic-panel goes from 33 entries to 0. The baseline is re-recorded because violations were *fixed*, which the ratchet requires — not to absorb new ones, which it forbids. Important (🟡): remove `box-shadow` from .modal in invitations-inbox.svelte. DESIGN.md reserves elevation shadows for floating surfaces; modal panels get none, since the backdrop provides separation. This PR rewrote the .modal block two lines above and should have caught it. Comment corrections (🟡/🟢): the --*-light rationale said those tokens "flip" lightness, which is imprecise — the real disqualifier is that they have no paired --*-light-foreground token. The badge comment's "~2.5-2.8:1" also omitted that white-on---destructive clears AA in light at 4.57:1; the binding constraint is the 2.86:1 dark case. Both now state the measured figures, including .status.error sitting at 2.88:1 in light. Not addressed: the rgba(0,0,0,0.5) overlay scrim (1 remaining baseline entry). It is the identical value used by all four other modals, and no overlay token exists. Inventing a one-off here would break that consistency; it belongs to the modals remediation issue. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Address review: tighten the badge-contrast comment Re-review nit (🟢, explicitly non-blocking): the comment enumerated five contrast ratios to justify one decision, and "white-on---destructive" read badly as a triple hyphen. Keep what stays useful at the call site — why a solid fill is not an option, and the one accepted sub-AA-large case — and drop the rejected-alternative figures, which are working notes rather than a standing constraint. They remain in the commit history and PR discussion if anyone needs to re-derive the decision. Comment-only; no behavioral change. Retained figures re-verified: solid fill is 2.55:1/2.86:1 in dark, and the tint clears 3:1 everywhere except .status.error at 2.88:1 in light (3.92/4.29/3.97 for the rest). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
Adds Stylelint as the CSS-side regression gate for the design system, closing the coverage hole described in #2589:
eslint-plugin-sveltecannot parse CSS inside Svelte<style>blocks, which is exactly where nearly all the design-system drift lives.The gate enforces three DESIGN.md constraints and is wired into
packages/desktop-app'squality:check/quality:fix, so it runs as part of the existing mandatory gate rather than as a separate, skippable script.What's enforced
rgb()/hsl()literals rejected on every color-bearing property.hsl(var(--token))— this codebase's token idiom — passes.box-shadowlimited to DESIGN.md's floating-surface value,none(modal panels), or a token-built shadow (focus rings).transitionlimited towidth 0.25s ease-out(sidebar) andopacity 0.2s ease(code-block buttons).animationand@keyframesrejected outright.Baseline, not a big-bang fix
The audit's violations are real and still present — 248 of them across 44 files. Failing the mandatory gate on all of them would block every unrelated change until the remediation issues (#2590–#2594) land.
So
scripts/check-design-tokens.tscompares Stylelint's output against a recorded baseline (design-tokens-baseline.json) and fails only on violations that are not in it. New drift is caught immediately; the existing backlog is worked down separately.The baseline is a ratchet: it is also an error for it to contain entries that no longer occur, so fixing a file forces the baseline down and the count can never silently grow back.
Notes on rule design
Two cases needed care, and both are covered by tests:
0 4px 6px -1px rgb(0 0 0 / 0.1), …, so a naive raw-color rule rejects the very value the spec mandates. It is exempted onbox-shadow, and matched whitespace-insensitively since the formatter wraps it across lines.box-shadowbut are not elevation.0 0 0 2px hsl(var(--ring) / 0.2)is correct, tokenized code; the shadow allowlist permits token-built shadows so these are not false positives.stylelint-declaration-strict-valuewas evaluated for the color rule and rejected:ignoreFunctions: trueletsrgba(0,0,0,0.5)through, andignoreFunctions: falserejectshsl(var(--token)). Neither expresses "a color function is fine iff its argument is a token," so the rule is a regex on Stylelint's built-indeclaration-property-value-disallowed-listinstead.Also note
customSyntax: postcss-htmlis applied per-extension rather than globally — applied globally it makes plain.cssfiles parse as empty and silently skips every rule on them, which would have excludednoderef.css(15 violations) from the gate entirely.Violations at time of landing
Per the acceptance criteria, this is the checklist the remediation issues can work against. Totals: 152 color, 12 shadow, 84 motion = 248 across 44 files.
src/lib/design/components/diagnostic-panel.sveltesrc/lib/components/collaboration/invitations-inbox.sveltesrc/lib/styles/noderef.csssrc/lib/components/viewers/ai-chat-pty-session.sveltesrc/lib/components/delete-confirmation-modal.sveltesrc/lib/components/settings/model-manager.sveltesrc/lib/components/conflict-toast.sveltesrc/lib/components/update-banner.sveltesrc/lib/components/onboarding/onboarding-wizard.sveltesrc/lib/components/subtree-access-denied-modal.sveltesrc/lib/components/viewers/ai-chat-node-viewer.sveltesrc/lib/components/layout/navigation-sidebar.sveltesrc/lib/components/layout/collection-sub-panel.sveltesrc/lib/components/pro-relogin-modal.sveltesrc/routes/+layout.sveltesrc/lib/components/viewers/query-node-viewer.sveltesrc/lib/components/autocomplete-modal.sveltesrc/lib/components/first-pro-consent-modal.sveltesrc/lib/components/layout/tab-system.sveltesrc/lib/components/query/query-editor.sveltesrc/lib/components/viewers/collection-node-viewer.sveltesrc/app.csssrc/lib/components/chat/chat-message.sveltesrc/lib/components/collaboration/collaboration-locked.sveltesrc/lib/components/node-tree.sveltesrc/lib/components/dev/version-badge.sveltesrc/lib/components/first-pro-consent-slot.sveltesrc/lib/components/ui/slash-command-dropdown/slash-command-dropdown.sveltesrc/lib/design/components/code-block-node.sveltesrc/lib/design/components/node-row.sveltesrc/lib/components/agent/pty-terminal.sveltesrc/lib/components/chat/chat-input.sveltesrc/lib/components/collaboration/collaboration-view.sveltesrc/lib/components/layout/database-switcher.sveltesrc/lib/components/layout/pane-manager.sveltesrc/lib/components/query/kanban-view.sveltesrc/lib/components/query/list-view.sveltesrc/lib/components/references/base-node-reference.sveltesrc/lib/components/references/node-ref-preview.sveltesrc/lib/components/status-bar.sveltesrc/lib/components/ui/node-autocomplete/node-autocomplete.sveltesrc/lib/components/viewers/date-node-viewer.sveltesrc/lib/design/components/backlinks-panel.sveltesrc/lib/design/components/theme-provider.svelteThe three violations in
src/app.cssare real: a leftover@keyframes blinkdemo animation and twobackground-color 0.15s easetransitions (inert anyway, since app.css disables transitions globally). The file is exempt from the color rule only — raw values are what a token is — and that exemption deliberately does not extend to motion or shadows.Testing
src/tests/design/stylelint-design-tokens.test.ts(30 tests) — rule behavior: what each rule accepts and rejects, that Svelte<style>blocks are parsed, that plain.cssfiles still lint, and that the app.css exemption does not widen into a blanket disable.src/tests/design/design-tokens-baseline.test.ts(8 tests) — baseline comparison: added vs fixed, duplicate counting (N identical violations are not masked by one baseline entry), and file-scoped keys.Verified end-to-end that the gate fails on a newly introduced violation and fails on a fixed violation until the baseline is re-recorded.
Acceptance criteria
<style>blocks in.sveltevar(--token)requiredbox-shadowrestricted to the DESIGN.md floating-surface value; modal panels usenonetransition/animation/@keyframesrestricted to the two approved casesquality:check/quality:fix— no separate skippable scriptsrc/app.cssfor color; its 3 motion violations are genuine findings, not config noisebun run quality:fixbun run test:allCloses #2589
🤖 Generated with Claude Code