# Design Token Linter

## Objective

Find the hardcoded colours, spacings, and radii that drifted away from the token set.

A check over the app's styles and markup that reports raw colour, spacing, typography, radius, and shadow values where an approved token exists.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Read the app's existing token definitions as the source of truth for the check, so adding a token to the design system automatically widens what the linter recognises without a second list to maintain.
2. Scan every place a value can be written: stylesheets, style objects, inline style attributes, utility class strings, and component props that take a raw value.
3. Report the nearest matching token alongside each finding, with the difference, so a developer sees that a 15px gap is one pixel from an existing step and can decide rather than re-derive.
4. Carve out the categories where raw values are legitimate — data visualisation series colours, media queries, third-party embed styling — and express those as documented, reviewable exceptions rather than blanket directory-wide silence.
5. Do not fail the build on the first run. Record the existing violations as an accepted baseline, block only new ones, and reduce the baseline deliberately; a check that turns the whole codebase red on day one gets removed on day two.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Values built from expressions or arithmetic will not match a token literally. Resolve what can be resolved statically and report the rest as unverifiable rather than as violations.
- Every finding must name the nearest token and the delta. A report that only says a value is untokenised leaves the developer to search the scale by hand, and most will not.
- Charts, illustrations, and third-party media legitimately need values outside the scale; these exceptions must be documented and reviewable, not achieved by excluding whole directories from the scan.
- Inline styles and dynamically composed class strings are where raw values hide most often — a scan of stylesheets alone will report a clean codebase that is nothing of the sort.
- Colours must be compared after normalisation, so the same colour written in different notations is recognised as one value and not reported twice or missed entirely.
- Reporting untokenised values is this feature's job; showing which token produced a rendered value at runtime belongs to Design Token Inspector, and general markup and accessibility rules belong to UI Lint Rules.
- A token that has been deprecated should be flagged in use as well, or the linter enforces conformance to a scale the design system has already moved on from.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] The check reads token definitions from the design system rather than a separate hardcoded list.
- [ ] Stylesheets, style objects, inline styles, utility class strings, and raw-value props are all scanned.
- [ ] Each finding names the nearest approved token and the difference from it.
- [ ] Computed and dynamic values are reported as unverifiable rather than as false violations.
- [ ] Legitimate exceptions are documented per case and visible in review.
- [ ] Existing violations are recorded as a baseline and only new violations fail the check.
- [ ] Uses of deprecated tokens are reported alongside untokenised values.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
