Skip to content

feat(linter): detect token name collisions for flat vs grouped keys#150

Open
Arshgill01 wants to merge 1 commit into
google-labs-code:mainfrom
Arshgill01:feat/collision-detection
Open

feat(linter): detect token name collisions for flat vs grouped keys#150
Arshgill01 wants to merge 1 commit into
google-labs-code:mainfrom
Arshgill01:feat/collision-detection

Conversation

@Arshgill01

Copy link
Copy Markdown

Closes #149

Requested by @davideast in #68:

One thing your PR has that #103 does not: collision detection for cases where a flat key and a grouped key produce the same name. That's a good idea and worth tracking.

What this does

forEachLeaf (merged in #103) enables arbitrary nesting depth for colors, rounded, and spacing tokens. As a side-effect it is now possible to write a DESIGN.md where two differently-structured keys resolve to the same symbol table entry with no diagnostic emitted. Two collision shapes exist:

Case 1 — Duplicate dot path

A flat string key whose literal value matches an existing nested token's dot-separated path:

colors:
  utility-info:
    50: "#EEF7FC"
  utility-info.50: "#FFFFFF"   # → error: Duplicate token path 'colors.utility-info.50' detected.

Case 2 — Flat/grouped name collision

A nested token whose path, when dots are replaced by hyphens, matches a flat key that is already registered:

colors:
  utility-info-50: "#EEF7FC"
  utility-info:
    50: "#FFFFFF"              # → error: Grouped color token flattens to 'utility-info-50', which is already defined.

In both cases the offending token is skipped (not written to the symbol table) and an error-severity finding is emitted so the user sees it at lint time, before the Tailwind v4 emitter processes the output. Behaviour is consistent across all three token categories.

Changes

File Change
packages/cli/src/linter/model/handler.ts Adds seenKeys (Set<string>) and seenNormalized (Map<string, string>) tracking inside the colors, rounded, and spacing Phase 1 forEachLeaf callbacks
packages/cli/src/linter/model/handler.test.ts 6 new test cases covering both collision types for all three token categories

Verification

bun test      → 288 pass, 0 fail
bun run lint  → tsc clean
bun run build → Bundled successfully

Adds duplicate and collision detection to the model builder for nested and flat token keys, preventing silent overwrites in the symbol table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(linter): token name collision detection for flat vs grouped keys

1 participant