fix(linter): orphaned-tokens should not flag MD3 paired tokens or baseline families - #59
Merged
davideast merged 1 commit intoMay 1, 2026
Conversation
…eline families Components that reference one MD3 token (e.g. `colors.primary`) imply the rest of the family (`on-primary`, `primary-container`, `primary-fixed-dim`, `inverse-primary`, etc.) is part of the same in-use semantic group. The rule now derives a family root for each color name and treats sibling tokens as referenced when any sibling is. The MD3 baseline families (primary, secondary, tertiary, error, surface, background, outline) are also exempt from the orphaned check because they are part of the standard contract a design system ships, not optional decoration. Custom tokens (e.g. `brand-blue`) still get flagged when truly unused. Result on the shipped examples: - atmospheric-glass: 43 orphan findings -> 0 - paws-and-paths: 33 orphan findings -> 0 - totality-festival: 38 orphan findings -> 0 Fixes google-labs-code#46
Collaborator
|
Thank you @mvanhorn! I'll get this merged in real quick to silence the annoying errors. This has me thinking about providing different configurations for linting depending on a specific system being followed. This would be opt-in and extensible. Let me know if you have any thoughts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the
orphaned-tokenslint rule aware of MD3 token families and the MD3 baseline contract, so the three shipped examples stop emitting 33-43 false-positive warnings each.Why this matters
Per #46:
Verified on
main:atmospheric-glasspaws-and-pathstotality-festivalThe example DESIGN.md files declare the full MD3 baseline palette but the canonical components only directly reference a small slice (
primary,on-primary,primary-fixed-dim,on-surface-variant). Tokens likeon-primary,primary-container,inverse-primaryaren't decoration — they're part of the same semantic family that consumers use at runtime. The rule was treating "no component direct reference" as "orphaned", which produces noise on every shipped example.Changes
packages/cli/src/linter/linter/rules/orphaned-tokens.ts:colorFamily(name)helper that reduces an MD3 token name to its family root by stripping prefixes (on-,inverse-) and suffixes (-container*,-fixed*,-dim,-bright,-tint,-variant). Custom tokens that don't match the patterns collapse to themselves, sobrand-bluekeeps getting flagged when unused.colors.primary), every sibling in the same family (on-primary,primary-container,on-primary-container,primary-fixed,primary-fixed-dim,on-primary-fixed,on-primary-fixed-variant,inverse-primary) is treated as part of the in-use group.packages/cli/src/linter/linter/rules/orphaned-tokens.test.ts:Testing
bun test src/linter/linter/rules/orphaned-tokens.test.ts— 6 pass, 0 fail.bun test(full suite) — 207 pass, 0 fail (was 206 before; +1 net new test that consolidated; full run added 4 new tests as above).bun run src/index.ts lint examples/<each>/DESIGN.mdconfirms the orphan count drops to 0 on all three shipped examples.The rule still flags genuinely-orphaned custom tokens (regression test asserts
brand-bluestill fires when defined but unreferenced).Fixes #46
This contribution was developed with AI assistance.