# UI Lint Rules

## Objective

Catch the interface mistakes that reviews keep missing, before they reach a branch.

A set of automated checks over the app's own markup and component usage for unlabelled controls, invalid variants, and unsafe interactive elements.

## 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. Start from the defects the app has actually shipped — read recent bug reports and review comments — and write rules for those, rather than adopting a large generic rule set that mostly reports things nobody intends to fix.
2. Cover the categories that reviewers reliably miss: controls without accessible names, variant or size values a component does not support, click handlers on non-interactive elements, headings that skip levels, and images with no alternative text decision.
3. Report each finding with the file, the line, what is wrong, and what to do instead. A rule that only names itself gets suppressed rather than fixed.
4. Provide a documented suppression mechanism that requires a reason on each exception, and surface the list of active suppressions, so exceptions are visible debt rather than an invisible amnesty.
5. Do not autofix anything ambiguous. Replacing a missing accessible name with a guess produces markup that passes the check and still fails the user, which is worse than the original failure because it stops being reported.

## 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

- A noisy rule set is worse than none, because the whole thing gets disabled after the first review that reports two hundred findings. Introduce rules as warnings, drive the count to zero, and only then make them errors.
- Autofixing must be limited to cases with exactly one correct outcome, such as normalising a renamed variant value; anything requiring a judgement about meaning must be reported for a human.
- Every rule needs a documented exception path with a required reason, and the exception must be scoped to the specific line rather than switching the rule off for a whole file.
- Rules must be versioned with the design system, so a component renaming its variants ships the rule change alongside it and does not break every consumer at once.
- Rules that need runtime information — computed contrast, actual focus order — cannot be answered from source alone; route those to a browser-based check and say clearly which layer owns each rule.
- Findings on generated or vendored code must be excluded by default, or the report is dominated by files nobody will edit.
- Raw colour, spacing, and radius values are the subject of Design Token Linter; consume its findings here rather than writing a second, differently-tuned set of token rules.

## 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

- [ ] Checks run on every change and report file, line, cause, and remedy for each finding.
- [ ] The rule set covers accessible names, invalid component variants, non-interactive click targets, and heading structure.
- [ ] Autofix applies only to cases with a single unambiguous correct result.
- [ ] Exceptions require a stated reason, are scoped to a line, and are listed somewhere visible.
- [ ] Rules are versioned with the design system and change alongside the components they check.
- [ ] The current codebase reports zero errors, so any new finding is genuinely new.
- [ ] Token-value rules are delegated to Design Token Linter rather than duplicated.
- [ ] 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.
