Skip to content

ESLint: Broaden no-unknown-ds-tokens to all strings and catch dynamic construction#75905

Merged
mirka merged 8 commits intotrunkfrom
eslint-no-unknown-ds-tokens-improvements
Feb 27, 2026
Merged

ESLint: Broaden no-unknown-ds-tokens to all strings and catch dynamic construction#75905
mirka merged 8 commits intotrunkfrom
eslint-no-unknown-ds-tokens-improvements

Conversation

@mirka
Copy link
Copy Markdown
Member

@mirka mirka commented Feb 25, 2026

What?

Two improvements to the no-unknown-ds-tokens ESLint rule:

  1. Broader scope: The rule now checks all string literals and template literals, not just those inside JSX style attributes.
  2. Dynamic construction check: Reports an error when --wpds-* token names are dynamically constructed via template literal expressions.

Why?

The previous rule only caught invalid tokens written directly in JSX style props. Tokens defined in plain objects or variables (then passed into style indirectly) were invisible to the rule. For example:

const gapTokens = {
	sm: 'var(--wpds-dimension-invalid-token)', // was not caught
};

Additionally, dynamically constructed token names like var(--wpds-dimension-gap-${size}) can't be statically verified for validity, and will also prevent the token fallback build plugin from injecting fallbacks.

How?

  • Removed the JSXAttribute[name.name="style"] ancestor constraint from the AST selector, so the rule matches --wpds-* in any string literal or template literal.
  • Split the selector into two: one for static strings (checked against the known token list as before) and one for template literals with expressions (reported with a dedicated dynamicToken message).

Testing Instructions

Try to modify a component file (e.g. packages/ui/src/stack/stack.tsx) to add invalid tokens, or dynamically generated tokens. They should error now.

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

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants