Skip to content

feat(lint): automate the rubric's §2 theming-target checks - #4774

Closed
cixzhang wants to merge 9 commits into
mainfrom
lint-theme-targets
Closed

cixzhang wants to merge 9 commits into
mainfrom
lint-theme-targets

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What this is

ESLint rules that automate the mechanically checkable part of the Component Audit Rubric's §2. Registered on the plugin, in neither shipped config, not wired into eslint.config.js — turning one on is a one-line change once we agree on the tier.

This PR used to be two things: proposed wiki text defining theming-target criteria, plus lint encoding it. The proposal is gone. The rubric now carries numbered §2 checks with their own severities and exceptions — T6, T7, T12, T26, T27 — so there is nothing left to propose. Every check here names the rubric id it automates, in the message text, so a report reads T6: theme target 'x-option' is on an element whose styles vary with… and the author can look up exactly what was applied.

Anything that could not name a rubric id was removed, rather than kept as a proposal:

Removed Why
missingPosition — the {parent}-{position}-{component} shape No published check states it, and it fires on banner-icon: a shipped public target with a codemod behind it, unrenameable
layoutOnlyRootTarget (55 hits) T7 exempts a component's root target outright — it is the component's address, not a seam anyone chose. Now skipped unconditionally instead of hidden behind an option
stateVariesOnlyLayout Encoded a refinement of T7 that T7 does not make, and it can no longer see the case that motivated it
inheritablePropertyOnChild (108 hits) Most hits are correct code — a caption should differ from its card. Kept only the render-prop-fallback form, where the divergence is structural

Also gone: the .github/copilot-instructions.md checklist this PR added. It restated rules the rubric owns, which is the duplication that caused a day of drift fixes last week. What is left there is the two facts a reviewer cannot get from the rubric alone — that T6 and T7 have no enforcer, and that these rules are in neither config, so a green pnpm lint says nothing about a new target.

The one worth having

underDeclaredState automates T6, which the rubric marks BLOCK, detects by grep, records as "historically the single most frequent finding", and has no lint rule for. It catches fooStyles[prop] inside stylex.props() with no prop in the sibling themeProps() call — a style-driving prop a theme cannot reach.

Its 20 hits are a real pre-existing backlog (Calendar, Code, CommandPaletteItem, FileInput, InputGroup, Link, MobileNav, MultiSelector, …), each needing a human call about which prop belongs on the target. Hence warn: at error it fails CI on main.

Measured on current main

Rule / check Rubric Count Proposed tier
theming-target-shape / underDeclaredState T6 20 warn
theming-target-shape / layoutOnlyTarget T7 7 warn
theming-target-shape / wrapperTarget T7 2 warn
theming-target-shape / unstyledTarget T7 0 error
theming-target-shape / targetOnRenderPropFallback T27 0 warn
theming-target-shape / inheritableOnRenderPropFallback T7/T27 0 warn
theming-target-name / appearanceInComponentSlot T27 2 warn
theming-target-name / stateSubTarget T26 0 error
themeprops-reflection / bypassedThemeProps T26 9 warn
themeprops-reflection / classNameOnly T12 3 warn
themeprops-reflection / clobberedByLaterProp T12 0 error
themeprops-reflection / droppedStateReflection, handAuthoredState T26 0 error

Counts re-run against main for this revision, not carried over. Every one of them moved over the eleven days this branch sat: T6 went 17 to 20, layout-only 6 to 7, wrapper 4 to 2, bypassed themeProps 7 to 9, className-only 4 to 3.

The live bug it was written for is gone

clobberedByLaterProp counted exactly one hit when this branch was cut:
RichTextEditor wrote className={className} after the themeProps spread, so
with no consumer className the theme class resolved to undefined. That file
has since moved to packages/richtext and was rewritten through mergeProps on
the way, and #4781 — the fix
this section used to point at — is closed. The check now measures 0 and ships as
a pure regression guard. MoreMenu's hand-built target is still open in
#4782; it is 2 of the 9
bypassedThemeProps hits.

Risk

None to consumers: no component source changes, and the rules run nowhere. The underDeclaredState backlog is the only thing that would bite, and only if someone enables it at error.

Testing

pnpm vitest run internal/eslint-plugin-astryx — 31 files, 653 tests, green. Counts above produced by running the rules over packages/{core,lab}/src/** through the ESLint Node API.

Rebased onto current main (41494fc). tsc --noEmit is identical to main in the same tree, 776 errors either way, all pre-existing.

@vercel

vercel Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 25, 2026 9:16pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 7, 2026
@cixzhang cixzhang changed the title feat(lint): prototype — lint theming targets against the authoring criteria Theming targets: the authoring criteria (proposed wiki text) + the lint we can automate Aug 7, 2026
freddymeta added a commit that referenced this pull request Aug 7, 2026
Review finding (cixzhang, #4540): the inter-row gap sat as margin-block on the
row box (contentWrapper) as calc(--tree-list-row-gap / 2) top and bottom,
assuming half+half sums to a full gap. It does not — neither the row wrapper
(position:relative) nor the <li> (margin/padding:0) establishes a BFC, so the
block margins collapse out and adjacent rows collapse to max(g/2,g/2)=g/2. The
lever delivered HALF its configured value (2px default rendered 1px) and half
leaked above the first row / below the last.

Move the gap onto rowWrapper as padding-block: padding cannot collapse, so the
full gap renders; rowWrapper carries no theme target, so the paintable
tree-list-item stays a pure paint seam (layout off the paint target, per the
theming-target guidelines in #4774); and the <li>s stay contiguous so the
guides still bridge. Retune the guide heights: the gap now lives inside the <li>
(padding), so verticalFull no longer adds the gap (100% already covers it, +1px
hairline bridge) and verticalLast clamps 100% - gap/2 to end at the row bottom.

Tests: assert the APPLIED verticalFull/verticalLast class on a row s own
connector (not a global-stylesheet regex, which passed regardless), and assert
the gap rides padding-block on the row wrapper and NOT margin-block on the paint
target. Verified the new geometry test fails on the pre-fix margin placement.
Changeset corrected: (1) no longer claims hierarchical trees are unchanged, and
(2) states the 2px default shifts every tree (matching List/DropdownMenu).
freddymeta added a commit that referenced this pull request Aug 10, 2026
… gap (#4540)

* feat(treelist): flush a fully flat tree + themeable inter-row gap

A leaf reserves the chevron-alignment column whenever the tree contains
any expandable item (a caret exists somewhere to align labels under), so
every row in a hierarchical tree renders exactly as before. Only a fully
flat tree — no expandable items at all — drops the empty chevron column
and renders its rows flush. The reserve decision is a whole-tree property
(computed once at the root), not a per-group one: an all-leaf group
nested under an expandable parent still reserves the column so its rows
stay indented past the parent's label.

Also adds a themeable --tree-list-row-gap (default 0px) for an inter-row
gap; the connector guides span the gap automatically and no longer
overhang the last row.

* feat(treelist): default the inter-row gap to a subtle 2px

Set --tree-list-row-gap's default to var(--spacing-0-5) (2px) so rows
have a light separation out of the box, instead of 0px. A theme can
still widen or close it via the tree-list target; the guide connectors
span the gap as before.

* test(treelist): use generateThemeTestCSS for the row-gap theme assertion

The row-gap test called generateThemeCSSFlat, a helper that no longer exists
after the rebase onto main (main renamed the theme-CSS helper). Point it at
generateThemeTestCSS, the surviving helper, so the row-gap CSS assertion runs.

* refactor(treelist): rename internal prop treeHasExpandableItems -> hasExpandableItems

Satisfies the @astryx/boolean-prop-naming lint rule (strict mode in CI
promotes it to an error), which requires boolean props to start with is/has.
Internal prop on TreeListItemInternalProps only — no public API change.

* fix(treelist): move row gap to collapse-proof padding on the row wrapper

Review finding (cixzhang, #4540): the inter-row gap sat as margin-block on the
row box (contentWrapper) as calc(--tree-list-row-gap / 2) top and bottom,
assuming half+half sums to a full gap. It does not — neither the row wrapper
(position:relative) nor the <li> (margin/padding:0) establishes a BFC, so the
block margins collapse out and adjacent rows collapse to max(g/2,g/2)=g/2. The
lever delivered HALF its configured value (2px default rendered 1px) and half
leaked above the first row / below the last.

Move the gap onto rowWrapper as padding-block: padding cannot collapse, so the
full gap renders; rowWrapper carries no theme target, so the paintable
tree-list-item stays a pure paint seam (layout off the paint target, per the
theming-target guidelines in #4774); and the <li>s stay contiguous so the
guides still bridge. Retune the guide heights: the gap now lives inside the <li>
(padding), so verticalFull no longer adds the gap (100% already covers it, +1px
hairline bridge) and verticalLast clamps 100% - gap/2 to end at the row bottom.

Tests: assert the APPLIED verticalFull/verticalLast class on a row s own
connector (not a global-stylesheet regex, which passed regardless), and assert
the gap rides padding-block on the row wrapper and NOT margin-block on the paint
target. Verified the new geometry test fails on the pre-fix margin placement.
Changeset corrected: (1) no longer claims hierarchical trees are unchanged, and
(2) states the 2px default shifts every tree (matching List/DropdownMenu).
@cixzhang
cixzhang force-pushed the lint-theme-targets branch from 823de50 to e7e7a45 Compare August 12, 2026 16:17
github-actions Bot added a commit that referenced this pull request Aug 12, 2026
@cixzhang
cixzhang force-pushed the lint-theme-targets branch from e7e7a45 to 3306fac Compare August 14, 2026 02:16
@cixzhang cixzhang changed the title Theming targets: the authoring criteria (proposed wiki text) + the lint we can automate feat(lint): automate the rubric's §2 theming-target checks Aug 14, 2026
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
Encode the mechanically checkable part of the wiki's "Principles for
authoring theming targets" as three rules, split by the severity they
can realistically ship at:

- @astryx/theming-target-shape — a target must sit on an element that
  paints. Flags a target on a layout-only box, on a paint-free wrapper
  around a composed Astryx component, and on an element with no styles
  at all. Uses #4758's stylex-style-source.js to read style objects
  across modules.
- @astryx/theming-target-name — {parent}-{position}-{component}: an
  appearance word in the component slot, a missing position segment,
  and state used as a name suffix.
- @astryx/themeprops-reflection — themeProps() read as `.className`
  (drops the data-* reflection) and hand-authored state data-*.

Shared analysis lives in theming-target.js: which themeProps() calls
land on an element, which stylex.props() arguments it applies, and
whether those declare paint, layout, or neither.

Not wired into eslint.config.js yet — prototype for review.
… rules

Adds the checks the theme-target inventory turned up as live bugs, plus
the RuleTester suites and the README section with measured counts.

- themeprops-reflection: `clobberedByLaterProp` (a `className` written
  after the spread overwrites the target — ChatSendButton.tsx:121 and
  RichTextEditor.tsx:527 render no theme class at all) and
  `bypassedThemeProps` (MoreMenu builds the class with stableClassName,
  so it can never carry state).
- theming-target-shape: state checks narrowed to RUNTIME state, so a
  size table that only moves padding is not a finding (principle 2
  requires size on the target whatever it changes); root targets moved
  behind `checkRootTargets` (55 of them are layout primitives).
- theming-target-name: the component-slot check applies to leaf
  components only, and never to a component's own root target —
  principle 3 makes `{component}-option` correct on a row primitive.
- 66 RuleTester cases across the three rules.

Measured on packages/ with the defaults: 19 findings total
(5 layoutOnlyTarget, 4 wrapperTarget, 3 appearanceInComponentSlot,
3 classNameOnly, 2 clobberedByLaterProp, 2 bypassedThemeProps).
…w guide

The criteria stay canonical in the wiki (Theming Infrastructure →
"Principles for authoring theming targets"); the repo cites them rather
than restating them.

- README: each check's row names the principle it enforces, plus a
  section on what is NOT lintable (P6, P7, P3 convergence, P5) — lint
  checks the shape of a target, a human decides whether it should exist.
- copilot-instructions.md: a reviewer/agent checklist for adding a
  target (does it paint? is the layout value declared? is it attached to
  the component? is the name compositional? is there a named consumer?),
  with the blocking items called out and the wiki linked as the source
  of truth.
- Each rule's file header cites the wiki page and the principle number.
Principle 4 was the one principle with no mechanical check, and its own
worked example — "a dedicated -label target that only wraps the fallback
span ... silently misses custom-rendered content" — turns out to be
detectable without any guess about design intent.

- targetOnRenderPropFallback: a target on the element a `render*`
  callback renders in place of. That is principle 4's named
  anti-pattern; the callback's output never carries the target.
- inheritableOnRenderPropFallback: inheritable typography/color on such
  a fallback, where hoisting it to the row target covers both paths.
- inheritablePropertyOnChild (opt-in, checkInheritableHoisting): the
  broad form — any inheritable property on an untargeted descendant of
  a target. 111 hits, most of them correct code (a Banner title and
  description SHOULD differ), so it stays off as an exploration aid.
  The narrow render-prop form is 0 on main and fires on #4628.

The render-prop predicate is intent-independent by construction: the
divergence between the two render paths is in the AST.
…edge

The README said a rule/wiki divergence should be resolved in the wiki's
favor. That is a standing licence for drift, written while both sides
are being authored. Replaced with the reconciliation: every divergence
found while encoding the principles was resolved on one side or the
other (audit in the PR description), and a future one is a bug to fix,
not a precedence question.

Also documents the two new principle-4 checks and the measured reason
the broad inheritable-hoisting form stays off (111 hits, most correct),
and adds "could the parent target reach it by inheritance?" to the
reviewer checklist.
…rule gaps

The theming-target checklist and the plugin README both described the
authoring criteria in a way that let the banner-icon case be resolved
backwards: checklist item 5 ("prefer inheritance") read as licensing a
per-status color on the wrapper with <Icon color="inherit">, which
contradicts item 3 ("never mint a wrapper to hold a target") and the
wiki's principle 1 ("the target belongs on the glyph, not the wrapper").

Inheritance has a precondition: it only arrives if the child does not set
the property directly on its own element. Every composed Astryx component
with a color/size prop does exactly that, so principle 4 is silent there
and principle 1 decides — the target goes on the component instance,
where a same-element rule in @layer astryx-theme beats the component's own
base styles by layer order. Measured in Chrome, not reasoned about; the
tables are in the PR description.

Also records the three rule-level gaps that applying this criteria
surfaces (wrapperTarget's paint precondition, the shape rule skipping
Astryx components, and missingPosition colliding with the shipped
banner-icon name). No rule behaviour changes here.

Fixes two Banner line references that main has since shifted.
…d empty-state names

Rebasing onto main turned up two false positives against code that landed
since: `focusOutlineProps.focusVisible(…)` forwards its arguments to
stylex.props(), so five targets on focusable elements read as `unstyledTarget`
(proposed `error`), and `{selector,multi-selector,typeahead}-empty-state` read
as `stateSubTarget` though "empty state" names a region, not a state of
another target. Re-measured every count in the README against current main.
The rubric's §2 has moved since these rules were written: it now carries
numbered checks with their own severities and exceptions, and T6, T7, T26,
T27 and T12 say exactly what a theming target must do. So the rules no
longer need to propose criteria — they can automate the ones that exist,
and the proposed wiki text goes away with them.

Every remaining check names its rubric id in its message, so a report reads
as "T6: ..." and the author can look the rule up. Anything that could not
name an id is gone: the {parent}-{position}-{component} shape (no published
rule states it, and it fires on the unrenameable banner-icon), the
layout-only root target (T7 exempts a component's root outright, the
state-seam-only-moves-layout check, and the broad inheritable-hoisting
exploration.

That leaves underDeclaredState as the one worth having: T6 is a BLOCK the
rubric detects by grep, records as the single most frequent theming finding,
and has no lint rule. It ships at warn — its 17 hits are a real backlog.
MSG
)
The tables were taken eleven days ago. Rebasing moved every one of them:
T6 under-declared state 17 -> 20, layout-only targets 6 -> 7, wrapper
targets 4 -> 2, bypassed themeProps 7 -> 9, className-only 4 -> 3.

clobberedByLaterProp is now 0: the RichTextEditor call site it counted
moved into packages/richtext and was rewritten through mergeProps on the
way, so the check ships as a pure regression guard with nothing to fix.
github-actions Bot added a commit that referenced this pull request Aug 25, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

Closing this prototype. Three large rules that are registered and documented but disabled are maintenance surface without enforcement. A future rule should start from one concrete regression, ship narrowly, and be enabled in the same change.

@cixzhang cixzhang closed this Aug 27, 2026
@github-actions
github-actions Bot deleted the lint-theme-targets branch August 27, 2026 09:11

This branch was successfully deployed

1 active deployment
Preview — 31e3756a Deployed Aug 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant