--- name: design-audit author: Andrew Wilkinson (github.com/ADWilkinson) description: Audit UI code for accessibility violations and visual consistency issues with scoring allowed-tools: Read, Glob, Grep, Bash, Task disable-model-invocation: true --- # /design-audit > **Quick Reference**: Detect UI files → Run accessibility checks (WCAG) → Run visual consistency checks → Score issues → Output prioritized report. Reviews frontend code for accessibility violations and visual inconsistencies. Returns a scored report with prioritized issues. ## Confidence Scoring Rate each issue found on a 0-100 scale: | Score | Meaning | Report? | |-------|---------|---------| | 0-25 | Might be intentional design choice | Skip | | 50 | Likely issue, but could be justified | Include with caveat | | 75-100 | Definitely an issue | Report as finding | **Only report issues with confidence ≥50.** High-confidence issues (≥75) should be prioritized. ## Arguments Parse user input for: - `` - Path to audit (default: detect recently changed files via git) - `--strict` - Enable strict mode (load ui-constraints rule) - `--category ` - Focus on specific category: accessibility, visual, performance - `--fix` - Attempt to auto-fix simple issues ## Step 1: Detect Files to Audit ### Recently changed files (default) ```bash git diff --name-only HEAD~5 -- '*.tsx' '*.jsx' '*.vue' '*.svelte' | head -20 ``` ### Specific path ```bash find -type f \( -name "*.tsx" -o -name "*.jsx" -o -name "*.vue" -o -name "*.svelte" \) | head -50 ``` ## Step 2: Run Accessibility Audit ### Critical Issues (WCAG Level A - must fix) **Missing alt text** ```bash # Find images without alt grep -rn '` or `aria-label` - Never rely on placeholder alone ### Serious Issues (WCAG Level AA - should fix) **Removed focus outlines** ```bash grep -rn 'outline.*none\|outline.*0' --include="*.css" --include="*.scss" --include="*.tsx" ``` - Never remove focus without replacement - Use `:focus-visible` with custom focus styles **Missing keyboard handlers** ```bash # onClick without onKeyDown on non-button elements grep -rn 'onClick' --include="*.tsx" | grep -E '` elements **Color contrast issues** ```bash # Common low-contrast patterns grep -rn 'text-gray-400\|text-slate-400\|opacity-50' --include="*.tsx" ``` - Text needs 4.5:1 contrast ratio (3:1 for large text) - Check with browser DevTools or Lighthouse ### Moderate Issues (WCAG Level AAA - consider) **Skipped heading levels** - Check that headings follow h1 → h2 → h3 order - Don't skip from h1 to h3 **Improper tabIndex** - `tabIndex > 0` disrupts natural tab order - Use `tabIndex={0}` or `tabIndex={-1}` only ## Step 3: Run Visual Consistency Audit ### Spacing Inconsistencies **Mixed spacing units** ```bash # Look for inconsistent spacing grep -rn 'margin.*px\|padding.*px' --include="*.tsx" --include="*.css" grep -rn 'p-[0-9]\|m-[0-9]\|gap-[0-9]' --include="*.tsx" ``` - Use design system spacing scale (Tailwind: 1, 2, 3, 4, 6, 8, 12, 16...) - Avoid arbitrary values like `p-[13px]` **Arbitrary z-index** ```bash grep -rn 'z-\[' --include="*.tsx" grep -rn 'z-index.*[0-9]' --include="*.css" ``` - Use fixed scale: 10, 20, 30, 40, 50 - Document what each level is for ### Typography Issues **Missing text-balance on headings** ```bash grep -rn ' Ref: WCAG 2.1 SC 2.1.1 Moderate (consider): src/components/Hero.tsx:3 h3 follows h1 (skipped h2) Fix: Use h2 or restructure heading hierarchy Visual Consistency: src/components/Modal.tsx:12 Arbitrary z-index (z-[999]) Fix: Use z-50 from standard scale src/components/Card.tsx:8 Missing hover state on interactive card Fix: Add hover:shadow-md or similar feedback Summary ------- Critical: 2 issues (-20 pts) Serious: 2 issues (-10 pts) Moderate: 1 issue (-2 pts) Visual: 2 issues (-6 pts) ───────────────── Total: 7 issues (-38 pts) Recommendation: Fix critical issues before shipping. Run with --fix to auto-fix simple issues. ``` ## Auto-Fix Capabilities When `--fix` is passed, attempt to fix: 1. **Missing alt on decorative images** → Add `alt=""` 2. **Missing aria-label on icon buttons** → Add placeholder `aria-label="TODO: add label"` 3. **Removed focus outlines** → Add `:focus-visible` with ring style 4. **Missing text-balance** → Add class to headings Report what was fixed vs what needs manual attention. ## False Positives (Do NOT Flag) Skip these common patterns that look like issues but are intentional: **Accessibility:** - Images with `role="presentation"` or `aria-hidden="true"` (intentionally decorative) - Buttons with `aria-label` set via props/variables (dynamic labels) - Inputs with labels connected via `aria-labelledby` pointing to another element - Custom focus styles using `ring-*` classes (valid focus replacement) - `outline-none` paired with `focus-visible:ring-*` (proper focus handling) **Visual Consistency:** - Design system utility classes that intentionally break the spacing scale - Z-index values in third-party component overrides - Animations with `prefers-reduced-motion` media query handling - Responsive spacing that intentionally varies by breakpoint **Framework-Specific:** - Next.js Image components (alt handled differently) - Headless UI / Radix components (accessibility built-in) - Icon libraries with their own accessibility patterns ## Thorough Mode (--thorough) When `--thorough` is passed, launch parallel validation agents: ```bash /design-audit --thorough src/components/ ``` **Phase 1: Multi-Agent Scan** Launch 3 specialized scans in parallel using Task tool: 1. **Accessibility Agent** (subagent_type: "frontend-developer"): Focus exclusively on WCAG violations. Check every interactive element. 2. **Visual Consistency Agent** (subagent_type: "frontend-developer"): Focus on spacing, typography, color, and component state consistency. 3. **Component Coverage Agent** (subagent_type: "frontend-developer"): Check for missing states (loading, error, disabled, empty). **Phase 2: Validate and Dedupe** - Consolidate findings from all agents - Remove duplicates - Validate each issue against false positive list - Assign confidence scores **Phase 3: Final Report** Output consolidated report with validated issues only. ## Common Patterns ```bash # Quick audit of recent changes /design-audit # Audit specific directory /design-audit src/components/ # Strict mode (loads ui-constraints rule) /design-audit --strict # Focus on accessibility only /design-audit --category accessibility # Auto-fix simple issues /design-audit --fix ```