Skip to content

Conversation

@natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Jan 23, 2026

Adds a new use-semantic-token ESLint rule that enforces semantic token usage in CSS properties.

Features

  • Centralized configuration via TOKEN_RULES array - single source of truth for:

    • Token detection (which patterns to match)
    • Property validation (which properties each category allows)
    • Autofix suggestions (reverse lookup: property → correct category)
  • Glob-like pattern matching for token paths:

    • content.* matches tokens.content.primary, tokens.content.onVibrant.light, etc.
    • interactive.*.content matches leaf content like tokens.interactive.chonky.embossed.accent.content
    • interactive.*.content.* matches nested content like tokens.interactive.chonky.debossed.neutral.content.primary
    • interactive.link.* matches all link tokens
  • Full token path in error messages for clarity

Current Rules

Content tokens (content.*, interactive.*.content, interactive.*.content.*, interactive.link.*) are only allowed on:

  • color
  • text-decoration-color
  • caret-color
  • column-rule-color
  • -webkit-text-fill-color
  • -webkit-text-stroke-color

Extensibility

To add a new category (e.g., background), simply add to TOKEN_RULES:

{
  name: "background",
  tokenPatterns: ["background.*"],
  allowedProperties: new Set(["background", "background-color"]),
},

TODO before merge

  • Fix existing violations
  • Add autofix support

Closes DE-729

@natemoo-re natemoo-re requested a review from a team January 23, 2026 21:21
@linear
Copy link

linear bot commented Jan 23, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jan 23, 2026
Refactors the rule to support generic token-to-property mapping with
centralized configuration via TOKEN_RULES array.

Changes:
- Replace ALLOWED_COLOR_PROPERTIES with TOKEN_RULES configuration
- Add glob-like pattern matching (e.g., 'content.*', 'interactive.*.content')
- Support deeply nested tokens like interactive.chonky.embossed.accent.content
- Add reverse mapping (PROPERTY_TO_RULE) for future autofix suggestions
- Update error messages to show full tokenPath instead of tokenName
- Add tests for interactive token patterns
@natemoo-re natemoo-re changed the title feat(lint): add use-semantic-token rule feat(lint): add use-semantic-token rule with extensible token mapping Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants