Skip to content

feat: CSS-correctness diagnostics for scoped <style> blocks - #1212

Closed
jonkwheeler wants to merge 2 commits into
octanejs:mainfrom
jonkwheeler:feat/css-correctness-analyzer
Closed

jonkwheeler wants to merge 2 commits into
octanejs:mainfrom
jonkwheeler:feat/css-correctness-analyzer

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Slice O3 of the typed-native-styling decomposition (tracked in #1204). Re-cut from #1195 — the core analyzer, no slice dependencies.

New Octane-owned analyzeStyleCorrectness pass emits collected diagnostics on both compile() and compileToVolarMappings:

  • octane-css-unknown-property (error): declarations checked against the mdn-data property registry; custom properties and vendor prefixes exempt
  • octane-css-shorthand-longhand-clash: direction-aware cascade pairs across same-block declarations, co-matching rules, scope chains, and statically resolved same-module apply sheets. Provable co-matches are errors; speculative pairs downgrade to warnings (pseudo-element identity and reset-then-restitute handled)
  • octane-css-unused-selector (warning): pruneCss match metadata distinguishes stale scoped-block pruning from designed class-map pruning; :global, theme mode, and dynamic tags excluded

/* octane-ignore [codes] */ before a rule or declaration suppresses a diagnostic on the collected channel; styleCorrectness: false disables the pass. Diagnostics-only: production codegen is byte-equal with checks on or off. DocPage.tsrx carries the dispositions the pass surfaces in-repo (longhand text-decoration-line, two octane-ignore resets) so the tree stays green.

Depends on mdn-data (added here). Editor/tsrx-tsc severity display is temporarily degraded until the @tsrx/* transport slice (tsrx T-A) publishes — octane analyze already surfaces severity natively.

Test plan

  • packages/octane/tests/style-correctness.test.ts (33 tests × octane + octane-prod)
  • packages/cli/tests/analyze.test.js (incl. collected kebab-code propagation moved here from the O1 commit)
  • Style regression sweep: scoped-styles-conformance (159×2), style-class-opt-in, return-style, deopt-style-patch — 354 tests
  • pnpm typecheck:files, pnpm format:files, pnpm sync (lockfile hash churn regenerated)
  • CI

Provenance

  • An agent produced this diff (agent-authored)

Re-cut mechanically from the validated diff in #1195; no redesign. Spike-token-seam test hunks deferred to the O5 slice (that file is added there).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
New compiler pass on every compile with scoped styles, but it is read-only and codegen is asserted byte-equal; main risk is false positives or perf on large style sheets and new diagnostic noise in CI/analyze.

Overview
Adds a diagnostics-only compile pass for scoped <style> blocks: analyzeStyleCorrectness runs on the adopted AST (before lowering) and attaches collected findings to both compile() and compileToVolarMappings without changing codegen output.

The pass reports octane-css-unknown-property (against mdn-data), octane-css-shorthand-longhand-clash (cascade-aware shorthand/longhand overlap, with errors vs warnings by provability), and octane-css-unused-selector (via the same pruneCss pipeline as codegen). Authors can suppress with octane-ignore comments or disable entirely via styleCorrectness: false. octane analyze now surfaces these under their kebab codes (with a CLI test); mdn-data is a new dependency. Lockfile hash churn is refreshed across parity audit metadata and eval manifests.

Reviewed by Cursor Bugbot for commit 041e91c. Bugbot is set up for automated code reviews on this repo. Configure here.

jonkwheeler and others added 2 commits September 21, 2026 09:31
New Octane-owned analyzeStyleCorrectness pass emits collected diagnostics on
both compile() and compileToVolarMappings:

- octane-css-unknown-property (error): declarations checked against the
  mdn-data property registry; custom properties and vendor prefixes exempt
- octane-css-shorthand-longhand-clash: direction-aware cascade pairs across
  same-block declarations, co-matching rules, scope chains, and statically
  resolved same-module apply sheets. Provable co-matches are errors;
  speculative pairs are warnings (pseudo-element identity and
  reset-then-restitute handled)
- octane-css-unused-selector (warning): pruneCss match metadata distinguishes
  stale scoped-block pruning from designed class-map pruning; :global, theme
  mode, and dynamic tags excluded

Adds /* octane-ignore [codes] */ suppression on the collected channel and a
styleCorrectness: false escape hatch. Diagnostics-only: production codegen is
byte-equal with checks on/off. DocPage carries the dispositions this pass
surfaces (longhand text-decoration-line, two octane-ignore resets).

Re-cut from feat/typed-native-styling (slice O3, tracked in octanejs#1204).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability labels Sep 21, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 041e91c. Configure here.

if (Array.isArray(computed)) {
for (const sub of computed) expandWriteSet(sub, out, seen);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intermediate shorthand clashes go undetected

Medium Severity

coversWrites requires every name in the loser's write set — including the loser's own shorthand token — to appear in the winner's expansion. expandWriteSet always inserts that token, but mdn-data computed lists only subproperties, so a broader shorthand such as border never contains an intermediate name like border-top. Pairs such as border-top then border therefore fail the subset check and are not reported, even though the later shorthand still resets everything the earlier one set.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 041e91c. Configure here.

}
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First selector pair sets clash severity

Medium Severity

evaluatePair reports the first co-matching selector pair and then returns. Grouped selectors such as h1, .title vs .title therefore emit a speculative warning from the h1 / .title pair and never see the later .title / .title pair, which is a provable co-match and should be an error.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 041e91c. Configure here.

}
}
return subject;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subject matching overstates provable clashes

Medium Severity

readSubject only records type, id, class, :not(), :global(), and pseudo-elements. Attribute selectors, :is() / :where() / :has() arguments, and state pseudo-classes are ignored, so those selectors look empty or identical. subjectSubsumes then treats two empty subjects as equal, and subjectsMustCoMatch promotes the pair to an error even when the selectors cannot always (or ever) hit the same element.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 041e91c. Configure here.

@jonkwheeler

Copy link
Copy Markdown
Contributor Author

Closing this slice draft for now: the typed-styling work is moving to an RFC first so the approach can be discussed with maintainers before asking for slice review. The branch and this re-cut remain intact; slices may be reopened or re-cut once the RFC settles the direction. Still tracked in the decomposition index (#1204).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant