Repository navigation
doctor: add stylex-compiler and token-literals checks - #6729
kiranbadam wants to merge 1 commit into
Conversation
stylex-compiler fails when no StyleX compiler integration is detectable: declared-but-not-installed, or neither a known compiler dependency nor a bundler config referencing StyleX. token-literals warns on raw color literals (hex / color functions with literal digits) in src/, mirroring the no-raw-color ESLint rule, while ignoring the theme layer, tests, and generated files. Fixes meta#6715, fixes meta#6720.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @kiranbadam! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Approval waits on an engineering owner's decision, and there are fixes to make either way.
No current spec covers either new doctor check. An engineering owner needs to provide or identify the governing spec for each one (what triggers it, and whether it fails or warns) and record that decision, for example by commenting /approve-spec <full head SHA> once a record covers it.
Blocking findings
stylex-compilerfails, and makesastryx doctorexit 1, on the prebuiltastryx.csssetup that Getting Started documents and thatspec:AST-080FR2/FR5 make the default (apps/example-nextjsexits 0 today and 1 with this change).- The new compiler package list duplicates
detectStylingSystem()inpackages/cli/foundation/agent-docs/agent-docs.mjswith a different list, soastryx initandastryx doctorcan disagree about the same project; please extend and call that one detector instead. token-literalswarns on the theme filesastryx theme addwrites tosrc/themes/<slug>, because thetheme/exemption missesthemes/, and on comments such as// see #1234, because it scans whole file text rather than string literals.pnpm -F @astryxdesign/cli typecheck:strict, which CI runs, reports 7 errors on the added code, because the JSDoc blocks sit on the constants instead of oncheckStylexCompiler,checkTokenLiteralsandscannableSourceFiles.- The fail message and the description say styles "silently do not apply" without a compiler, but Astryx component styles come from
astryx.cssand an uncompiledstylex.create()throws at runtime, so the wording should describe what actually happens. - The
token-literalsfix tells builders to run theno-raw-colorESLint rule, which ships only inside this repository and is not published. - The
token-literalsresult overstates its coverage: it reports "in 5 file(s)" when it stopped at five, and it passes with "No raw color literals found" when it stopped after 300 files.
The branch also conflicts with main in both doctor files and needs a rebase.
[Automated review]
| } | ||
|
|
||
| const installed = declared.filter(name => !notInstalled.includes(name)); | ||
| if (installed.length === 0 && wiredConfigs.length === 0) { |
There was a problem hiding this comment.
This fails, and makes doctor exit 1, on the prebuilt astryx.css setup that Getting Started documents and that spec:AST-080 FR2/FR5 make the complete default with no compiler (apps/example-nextjs goes from exit 0 to exit 1). Gate it on a non-type-only @stylexjs/stylex import in project source, the condition spec:AST-048 FR20 uses.
| * @param {DoctorContext} ctx | ||
| * @returns {DoctorCheck} | ||
| */ | ||
| const STYLEX_COMPILER_PACKAGES = [ |
There was a problem hiding this comment.
detectStylingSystem() in packages/cli/foundation/agent-docs/agent-docs.mjs already owns which packages count as StyleX compilers, and its list shares only @stylexjs/babel-plugin with this one. Please extend or export that one detector and call it here, so astryx init and astryx doctor agree.
| 'webpack.config.cjs', | ||
| ]; | ||
|
|
||
| export function checkStylexCompiler(ctx) { |
There was a problem hiding this comment.
typecheck:strict (run in CI) reports implicit-any ctx here and at line 1217, plus errors at lines 1187, 1190, 1301 and 1302. The JSDoc block above STYLEX_COMPILER_PACKAGES belongs on this function, and the same goes for the block above TOKEN_LITERAL_HEX.
| label, | ||
| status: 'fail', | ||
| message: | ||
| 'No StyleX compiler integration detected. Astryx styles are compiled at build time — without the compiler, stylex.create() output is never generated and styles silently do not apply.', |
There was a problem hiding this comment.
Astryx component styles come from the prebuilt astryx.css, and an uncompiled stylex.create() throws at runtime in @stylexjs/stylex 0.19 (Unexpected 'stylex.create' call at runtime), so styles do not "silently" fail. Suggested wording: "This project's source imports @stylexjs/stylex, but no StyleX compiler is configured; stylex.create() calls throw at runtime until one is."
| const TOKEN_LITERAL_SKIP_FILE = /\.(test|spec|stories|doc|sandbox)\./; | ||
| /** The theme layer owns color values by design; never flag it. Paths here are | ||
| * relative to src/, so `theme/` alone identifies the layer. */ | ||
| const TOKEN_LITERAL_THEME_LAYER = /(^|\/)theme\//; |
There was a problem hiding this comment.
astryx theme add writes to src/themes/<slug> by default, and this pattern does not match themes/. Right after astryx theme add neutral, this check warns about neutralTheme.ts and two generated palette files. Consider /(^|\/)themes?\//.
| } catch { | ||
| continue; | ||
| } | ||
| let hit = TOKEN_LITERAL_HEX.test(text); |
There was a problem hiding this comment.
This tests the whole file text, so a comment such as // see #1234 or #6715 counts as a raw colour. no-raw-color.js reads only string and template literals for exactly this reason.
| label, | ||
| status: 'warn', | ||
| message: `Raw color literals bypassing design tokens in ${offenders.length} file(s): ${shown}${more}. Hardcoded colors do not retint with the theme.`, | ||
| fix: 'Replace literals with theme tokens (e.g. colorVars / shadowVars from your theme), or run the no-raw-color ESLint rule to find every occurrence.', |
There was a problem hiding this comment.
The no-raw-color rule lives in the private internal/eslint-plugin-astryx package, so a consumer cannot run it. Point to something they have (for example astryx docs tokens) or drop this clause.
| id, | ||
| label, | ||
| status: 'pass', | ||
| message: 'No raw color literals found in src/ — colors flow through design tokens.', |
There was a problem hiding this comment.
This also passes after the scan stopped at 300 files, so an offender in file 301 is reported as "No raw color literals found". Report info (not fully inspected) when the limit cut the scan short. The warn message likewise says "in 5 file(s)" when it stopped counting at five.
|
(Posted by Cindy's agent.) Thanks for this, @kiranbadam, and for keeping it current. Two things to resolve before it can move forward. First, the stylex-compiler check would flag apps that are set up correctly: the setup records support loading Core's prebuilt stylesheet with no StyleX compiler at all, and |
|
I'll run a full review to re-check this with your note. |
There was a problem hiding this comment.
Changes are needed before this can move forward, and an engineering owner has already set the direction: narrow both checks to what existing tooling does not cover.
Blocking findings
stylex-compilerfails, and makesastryx doctorexit 1, on the prebuiltastryx.csssetup that needs no StyleX compiler (spec:AST-080FR2/FR5), so it should fire only on what that setup and doctor's stylesheet check do not cover, such as source that imports@stylexjs/stylexwith no compiler configured.- As an engineering owner noted here,
token-literalsreports what theno-raw-colorlint rule already reports, so narrow it to what that rule does not cover or drop it. - The new compiler package list duplicates
detectStylingSystem()inpackages/cli/foundation/agent-docs/agent-docs.mjswith a different list, soastryx initandastryx doctorcan disagree; please extend and call that one detector instead. token-literalswarns on the theme filesastryx theme addwrites tosrc/themes/<slug>and on comments such as// see #1234, because its exemption matches onlytheme/and it scans whole file text rather than string literals.pnpm -F @astryxdesign/cli typecheck:strict, which CI runs, reports 7 errors on the added code, because the JSDoc blocks sit on the constants instead of oncheckStylexCompiler,checkTokenLiteralsandscannableSourceFiles.- The fail message and the description say styles "silently do not apply" without a compiler, but Astryx component styles come from
astryx.cssand an uncompiledstylex.create()throws at runtime, so the wording should describe what actually happens. - The
token-literalsfix tells builders to run theno-raw-colorESLint rule, which ships only inside this repository and is not published. - The
token-literalsresult overstates its coverage: it says "in 5 file(s)" when it stopped counting at five, and passes with "No raw color literals found" when it stopped after 300 files.
The branch also conflicts with main in both doctor files and needs a rebase. A narrowed version gets a fresh review.
Claims and files checked
Review mode: full; reason: recipe-changed (many rules)
- Release note:
stylex-compilerfails when a compiler is declared but not installed, or when there is neither a compiler dependency nor a config mentioning StyleX: verified (doctor.mjs:1088-1108, tests). - Release note:
token-literalswarns on raw colour literals undersrc/: verified, but it also flags comments and the theme filesastryx theme addwrites. - Description: without a compiler, StyleX styles silently do not apply and the app renders unstyled with no error: false (
stylex.create()throws at runtime; Core styles come fromastryx.css). - Description: doctor reported a clean bill of health while styles were silently broken: false for the same reason.
- Description: known compiler packages are recognised, including
@astryxdesign/build: verified (doctor.mjs:1027-1037); the list differs fromdetectStylingSystem(). - Description: the check passes when a bundler config references StyleX: verified (test;
doctor.mjs:1078-1086). - Description: a missing compiler means no generated output, hence fail rather than warn: false; the prebuilt default needs no compiler (
spec:AST-080FR2). - Description:
token-literalswarns rather than fails: verified (status: 'warn'). - Description: its patterns mirror the
no-raw-colorrule: partly false; it scans whole file text, comments included, with a narrower theme exemption. - Description: the theme layer, tests, stories, docs and generated files are excluded: partly;
src/theme/, those file names and build-output folders are skipped, butsrc/themes/is not. - Description: colour functions built from passed-in values are not flagged: verified (test).
- Description:
stylex-compilerreports info when Core is missing: verified (doctor.mjs:1063-1070). - Description: at most 300 files and 5 offenders: verified, but the result text overstates what was read.
- Description: no new flags, config changes or caller decisions: partly false; doctor gains an exit-1 path on the default setup.
- Description: 59 tests pass and ESLint is clean on the changed files: verified.
- Description: the repository checks pass: the changeset check passes; the other repository checks were not rerun.
.changeset/doctor-style-checks.md: clear.packages/cli/api/doctor/doctor.mjs: the findings above.packages/cli/api/doctor/doctor.test.mjs: no finding; the tests pass but do not cover the prebuilt-stylesheet setup,astryx theme addoutput or comments.
User need
Agent-built Astryx apps fail in two ways
astryx doctornever caught. First, StyleX styles silently don't apply when the compiler integration is missing or broken — the app renders unstyled with no error, and the builder blames the theme or their own code. Second, agents hardcode color literals (#6b7280,rgba(0,0,0,0.12)) instead of design tokens, so the app doesn't retint with the theme. Both are first-build-quality killers: the builder's firstastryx buildlooks wrong and they can't tell why. No existing check covers either;doctorreported a clean bill of health while styles were silently broken.Problem and solution fit
stylex-compilercheck: fails when no StyleX compiler integration is detectable. It recognizes known compiler packages (@stylexjs/babel-plugin,@stylexjs/unplugin, bundler variants,@astryxdesign/build), fails when a compiler is declared but not installed, and passes when a bundler config references StyleX (the standard wiring). Without the compiler,stylex.create()output is never generated — hence fail, not warn.token-literalscheck: warns (not fails — literals still render) when project source undersrc/contains raw hex colors or color functions with literal digits. Patterns mirror the existingno-raw-colorESLint rule; the theme layer (src/theme/), tests, stories, docs, and generated files are excluded, and color functions built from handed-in values (rgba(${r}, ${g}, ${b}, ${a})) are not flagged.Current specification
Fixes #6715 (doctor should fail when the StyleX compiler is missing) and #6720 (doctor should warn on raw color literals). Both checks are appended to
SYNC_CHECKSinpackages/cli/api/doctor/doctor.mjs, following the existing check contract ({id, label, status, message, fix}).Public delta and caller burden
astryx doctoroutput gains two checks:stylex-compiler(fail/info) andtoken-literals(warn/pass/info). No new flags, no config changes, no caller decisions — both run as part of the existingdoctorcommand.stylex-compilerisinfo(skipped) when@astryxdesign/coreisn't installed, matching the other core-dependent checks.core-installed,docs-progressive-disclosure).Design and alternatives
token-literalsscans at most 300 source files and reports at most 5 offenders: a bounded, readable summary rather than an exhaustive lint. The exhaustive path remains theno-raw-colorESLint rule, which the check'sfixtext points to.Evidence
packages/cli/api/doctor/doctor.test.mjs(59 total in the file, all pass):stylex-compiler: info when core absent; fail when no integration detectable; fail when declared but not installed; pass when installed; pass when a bundler config references StyleX.token-literals: info when core absent; warn on raw hex; warn onrgba(...)with literal digits; pass on runtime-variable-only color functions; pass when only theme/test files contain literals; pass on token-based styles.npx vitest run --project node packages/cli/api/doctor/doctor.test.mjs— 59/59 pass.pnpm check:repo— clean (includes changesets, knowledge, package boundaries).Scope
Testing
npx vitest run --project node packages/cli/api/doctor/doctor.test.mjs— 59/59 pass.pnpm check:repo— all repo checks pass.eslintonpackages/cli/api/doctor/doctor.mjsanddoctor.test.mjs— 0 errors, 0 warnings.Closes #6715
Closes #6720