Skip to content

feat(lint): flag div/span wrappers that only style an Astryx component - #4758

Merged
cixzhang merged 2 commits into
mainfrom
no-style-wrappers
Aug 7, 2026
Merged

cixzhang merged 2 commits into
mainfrom
no-style-wrappers

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

#4752 fixed a caret that sat a few pixels high. The cause was not the caret — it
was the <span> around it: a wrapper whose only job was to carry
rtlStyles.mirror, which put an extra element between the button's flex
centering and the Icon. Every Astryx component extends BaseProps, so it takes
xstyle; a styling-only wrapper is a DOM node the component contract never asked
for, and it silently changes the parent's flex/grid child relationship.

The guidance already existed (packages.instructions.md even uses
<Divider xstyle={…} /> as the example) and it still shipped twice in the same
component. So this adds the mechanical check to go with the prose.

What

@astryx/no-style-only-wrapper — reports a div/span whose attributes are
only styles (a stylex.props() spread, className, style, optionally key)
wrapping a single Astryx component, and offers a suggestion that moves the
styles onto the child's xstyle. It is a suggestion, never a --fix: removing a
node can shift layout, so a human confirms.

The rule stays quiet where the wrapper is doing real work — more than one child,
a host or non-Astryx child, anything semantic on the wrapper (role, aria-*,
data-*, ref, a handler, {...rest}), a child that renders no root element
(overlays, providers), or styles that are structural: display, the flex/grid
container properties, gap, padding. Those change the child's own formatting
context or the space around its border box, so the wrapper is not redundant.

To classify structural styles honestly it has to read the style object, which is
usually in another module (../utils → rtlStyles, ./shared → styles).
stylex-style-source.js does that lookup with a brace-balanced scan that follows
barrel re-exports. Without it the rule mislabels five Schedule wrappers that are
genuine grid/flex containers.

Docs — the same rule stated for reviewers and agents: a repo-wide expectation
plus a worked example in the Copilot instructions, and the styling bullet in the
packages instructions expanded with the failure mode and the legitimate cases.
Internal review guidance only — the end-user-facing astryx docs principles text
is deliberately untouched.

Risk

No runtime code changes and nothing consumer-visible — lint config, an internal
plugin, and internal review guidance. No changeset for that reason.

The rule runs as a warning in both tiers, not an error: 25 wrappers in
packages/core predate it (Carousel, Chat, Lightbox, MobileNav, Pagination,
PowerSearch, Switch, Table/rowExpansion, TopNav). Flipping it to error in the
strict tier is a one-line change once those are migrated — the path
no-physical-properties took. I deliberately did not grandfather those files
with allowFiles: #4752's wrapper was a new wrapper in a file that already had
one, and a file-level exemption would have missed it exactly.

Test files are exempt — sizing scaffolding around a component under test is not
shipped DOM.

Testing

37 new tests (27 rule cases, 10 for the cross-file style reader), 245 plugin
tests green. CI=true eslint . across the repo: 0 errors, 25 warnings, all from
this rule — the two spans #4752 is fixing are among them, so the rule
demonstrably catches the case it was written for.

Follow-up worth doing separately: migrate those 25 sites and flip the rule to
error. Each one moves real styles onto a component root, so it wants its own
visual check rather than riding along here.

Flags a div/span that exists only to style a single Astryx component;
those components extend BaseProps, so the styles belong on xstyle.
@vercel

vercel Bot commented Aug 6, 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 6, 2026 5:17pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 6, 2026
Copilot instructions (repo-wide + packages) and the eslint plugin README.
Internal review guidance only — the end-user-facing CLI principles doc is
deliberately left alone.
@cixzhang
cixzhang force-pushed the no-style-wrappers branch from 836ce76 to 02cd548 Compare August 6, 2026 17:15
@cixzhang
cixzhang marked this pull request as ready for review August 7, 2026 00:11
@cixzhang
cixzhang requested a review from imdreamrunner as a code owner August 7, 2026 00:11
@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 merged commit 5c851ad into main Aug 7, 2026
30 of 31 checks passed
@github-actions
github-actions Bot deleted the no-style-wrappers branch August 7, 2026 06:27
nynexman4464 added a commit that referenced this pull request Aug 7, 2026
pr-rtl ran the RTL audit unfiltered on every PR, sweeping all ~1400 core-*
stories in ~26 minutes — the long pole of PR CI by 2.5x, and paid even by PRs
that touch no component. On #4758 (eslint-plugin + docs only) the sibling
pr-a11y correctly skipped in 0s while pr-rtl audited the whole library.

Scope the job like pr-a11y: gate on check-components.has_components, download
pr-analysis, and pass the changed components to the audit's --filter. Every
piece already existed — check-components publishes has_components,
analyze-pr.js writes newComponents/modifiedComponents, rtl-audit.mjs parses
--filter — pr-a11y used all three, pr-rtl used none. New components stay
covered via newComponents.

Also short-circuit D5 before the RTL page load. autoPositionalMirror loaded
LTR, always loaded RTL, then checked whether either produced candidates. With
no LTR candidate there is nothing to measure against, and 1378 of 1394 stories
have none, so this drops ~half of D5's page loads. It also closes a silent
false-pass: the old `ltr === 0 && rtl === 0` guard let one-sided stories reach
a compare loop that runs min(ltr, rtl) = 0 times and reported "pass" having
compared nothing.

Adds a root rtl:audit script for parity with a11y:audit, which also avoids a
footgun — pnpm -F IS --filter, so `pnpm -F @astryxdesign/storybook rtl-audit
--filter Avatar` has pnpm eat the flag and audit everything.

Coverage for untouched components comes from the weekly full sweep in the
stacked follow-up, mirroring the pr-a11y / a11y-weekly.yml split.

Test plan: verified against the Storybook artifact from run 31122588220 (same
1394 stories). `pnpm rtl:audit -- --filter Avatar,TableTree` finishes in 19.7s
and reproduces that run's Avatar verdicts exactly (cand=3/14/4/6/14). Full
unfiltered sweep of the unmodified script on the same input: 1724s, matching
CI's counts (AUTO 11/0/114, PM 16/0/1378). ci.yml parses; pnpm check:repo
clean; prettier-clean.
nynexman4464 added a commit that referenced this pull request Aug 7, 2026
pr-rtl ran the RTL audit unfiltered on every PR, sweeping all ~1400 core-*
stories in ~26 minutes — the long pole of PR CI by 2.5x, and paid even by PRs
that touch no component. On #4758 (eslint-plugin + docs only) the sibling
pr-a11y correctly skipped in 0s while pr-rtl audited the whole library.

Scope the job like pr-a11y: gate on check-components.has_components, download
pr-analysis, and pass the changed components to the audit's --filter. Every
piece already existed — check-components publishes has_components,
analyze-pr.js writes newComponents/modifiedComponents, rtl-audit.mjs parses
--filter — pr-a11y used all three, pr-rtl used none. New components stay
covered via newComponents.

Also short-circuit D5 before the RTL page load. autoPositionalMirror loaded
LTR, always loaded RTL, then checked whether either produced candidates. With
no LTR candidate there is nothing to measure against, and 1378 of 1394 stories
have none, so this drops ~half of D5's page loads. It also closes a silent
false-pass: the old `ltr === 0 && rtl === 0` guard let one-sided stories reach
a compare loop that runs min(ltr, rtl) = 0 times and reported "pass" having
compared nothing.

Adds a root rtl:audit script for parity with a11y:audit, which also avoids a
footgun — pnpm -F IS --filter, so `pnpm -F @astryxdesign/storybook rtl-audit
--filter Avatar` has pnpm eat the flag and audit everything.

Coverage for untouched components comes from the weekly full sweep in the
stacked follow-up, mirroring the pr-a11y / a11y-weekly.yml split.

Test plan: verified against the Storybook artifact from run 31122588220 (same
1394 stories). `pnpm rtl:audit -- --filter Avatar,TableTree` finishes in 19.7s
and reproduces that run's Avatar verdicts exactly (cand=3/14/4/6/14). Full
unfiltered sweep of the unmodified script on the same input: 1724s, matching
CI's counts (AUTO 11/0/114, PM 16/0/1378). ci.yml parses; pnpm check:repo
clean; prettier-clean.
nynexman4464 added a commit that referenced this pull request Aug 7, 2026
pr-rtl ran the RTL audit unfiltered on every PR, sweeping all ~1400 core-*
stories in ~26 minutes — the long pole of PR CI by 2.5x, and paid even by PRs
that touch no component. On #4758 (eslint-plugin + docs only) the sibling
pr-a11y correctly skipped in 0s while pr-rtl audited the whole library.

Scope the job like pr-a11y: gate on check-components.has_components, download
pr-analysis, and pass the changed components to the audit's --filter. Every
piece already existed — check-components publishes has_components,
analyze-pr.js writes newComponents/modifiedComponents, rtl-audit.mjs parses
--filter — pr-a11y used all three, pr-rtl used none. New components stay
covered via newComponents.

Also short-circuit D5 before the RTL page load. autoPositionalMirror loaded
LTR, always loaded RTL, then checked whether either produced candidates. With
no LTR candidate there is nothing to measure against, and 1378 of 1394 stories
have none, so this drops ~half of D5's page loads. It also closes a silent
false-pass: the old `ltr === 0 && rtl === 0` guard let one-sided stories reach
a compare loop that runs min(ltr, rtl) = 0 times and reported "pass" having
compared nothing.

Adds a root rtl:audit script for parity with a11y:audit, which also avoids a
footgun — pnpm -F IS --filter, so `pnpm -F @astryxdesign/storybook rtl-audit
--filter Avatar` has pnpm eat the flag and audit everything.

Coverage for untouched components comes from the weekly full sweep in the
stacked follow-up, mirroring the pr-a11y / a11y-weekly.yml split.

Test plan: verified against the Storybook artifact from run 31122588220 (same
1394 stories). `pnpm rtl:audit -- --filter Avatar,TableTree` finishes in 19.7s
and reproduces that run's Avatar verdicts exactly (cand=3/14/4/6/14). Full
unfiltered sweep of the unmodified script on the same input: 1724s, matching
CI's counts (AUTO 11/0/114, PM 16/0/1378). ci.yml parses; pnpm check:repo
clean; prettier-clean.
cixzhang added a commit that referenced this pull request Aug 12, 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.
cixzhang 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.
cixzhang added a commit that referenced this pull request Aug 25, 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.

This branch was successfully deployed

1 active deployment
Preview — 02cd548c Deployed Aug 6, 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