From 430a03b60f58e1e5ffd182f1be23b50d421e46da Mon Sep 17 00:00:00 2001 From: XingY Date: Tue, 24 Mar 2026 10:52:31 -0700 Subject: [PATCH] Add Claude Skill for checking WCAG compliance --- .claude/skills/code-review-react/skill.md | 8 +- .claude/skills/wcag-compliance/skill.md | 123 +++++++++++ .../wcag-compliance/wcag-22-checklist.md | 203 ++++++++++++++++++ 3 files changed, 331 insertions(+), 3 deletions(-) create mode 100644 .claude/skills/wcag-compliance/skill.md create mode 100644 .claude/skills/wcag-compliance/wcag-22-checklist.md diff --git a/.claude/skills/code-review-react/skill.md b/.claude/skills/code-review-react/skill.md index 3cb2a78a6f..5f9cc672b3 100644 --- a/.claude/skills/code-review-react/skill.md +++ b/.claude/skills/code-review-react/skill.md @@ -20,6 +20,8 @@ Stick to the checklist below for every applicable file and mode. Apply only the ## Checklist See [.agents/review-checklists/common.md](../../../.agents/review-checklists/common.md) for reviewer priority and standard review format, and [.agents/review-checklists/react/code-quality.md](../../../.agents/review-checklists/react/code-quality.md), [.agents/review-checklists/react/performance.md](../../../.agents/review-checklists/react/performance.md), [.agents/review-checklists/react/business-logic.md](../../../.agents/review-checklists/react/business-logic.md) for the living checklist split by category—treat it as the canonical set of rules to follow. +Additionally, check for WCAG 2.2 Level AA accessibility violations using [wcag-22-checklist.md](../wcag-compliance/wcag-22-checklist.md). Use category **Accessibility** for these findings. Prioritize urgent WCAG criteria (missing alt text, keyboard traps, no focus indicators, missing form labels, broken ARIA) alongside Correctness-level issues. + Use the rule's `Urgency` to place findings in the "urgent issues" vs "suggestions" sections. ## Review Process @@ -66,7 +68,7 @@ unchanged code only if they directly interact with or are affected by the change 1. Open the relevant component/module. Gather all lines. 2. For each applicable checklist rule, evaluate the code against the rule text, confidence threshold, and exceptions/false positives before deciding to flag it. 3. For each confirmed violation, capture evidence (exact snippet and/or file/line), record the rule's primary category, and note confidence briefly. -4. Compose the review section per the template below. Group findings by **Urgency** section first (urgent issues, then suggestions). Within each section, order findings by the checklist primary category priority: **Correctness**, then **Maintainability**, then **Style**. +4. Compose the review section per the template below. Group findings by **Urgency** section first (urgent issues, then suggestions). Within each section, order findings by the checklist primary category priority: **Correctness**, then **Accessibility**, then **Maintainability**, then **Style**. ## Required output When invoked, the response must exactly follow one of the two templates: @@ -79,7 +81,7 @@ Found urgent issues that need to be fixed: ## 1 FilePath: line Evidence: -Category: +Category: Confidence: - Exceptions checked: @@ -95,7 +97,7 @@ Found suggestions for improvement: ## 1 FilePath: line Evidence: -Category: +Category: Confidence: - Exceptions checked: diff --git a/.claude/skills/wcag-compliance/skill.md b/.claude/skills/wcag-compliance/skill.md new file mode 100644 index 0000000000..388f4e1b79 --- /dev/null +++ b/.claude/skills/wcag-compliance/skill.md @@ -0,0 +1,123 @@ +--- +name: wcag-compliance +description: "Review frontend code for WCAG 2.2 Level AA accessibility compliance. Checks semantic HTML, ARIA usage, keyboard navigation, color contrast, focus management, and more. Supports --full flag for complete file/directory review; defaults to staged changes when a path is provided." +--- + +# WCAG 2.2 Accessibility Compliance Review + +## Intent +Use this skill whenever the user asks to check accessibility or WCAG compliance of frontend code (`.tsx`, `.ts`, `.js`, `.jsx`, `.scss`, `.css`, `.jsp`, `.jspf` files). Support three review modes: + +1. **Pending-change review** -- bare invocation with no arguments; inspects staged/working-tree + files slated for commit across all repos. +2. **Path review (default)** -- a file or directory path is provided (no flag); reviews only the + git staged/working-tree changes for that path. +3. **Full review** -- a file or directory path is provided with `--full`; reviews the entire file + contents (or all matching files in a directory) regardless of git status. + +Apply only the WCAG 2.2 Level AA checklist below. Focus on issues that can be detected through static code review. + +## Checklist +See [wcag-22-checklist.md](wcag-22-checklist.md) for the full set of criteria organized by principle. + +Each rule has an **Urgency** level: +- **urgent** -- Violations that block users from accessing content or functionality. +- **suggestion** -- Improvements that enhance the experience but don't fully block access. + +## Review Process + +**Argument parsing:** + +Parse the invocation arguments to extract: +- An optional flag: `--full` +- An optional path: a file path or directory path + +**File discovery:** + +- **No path, no flag (bare invocation):** Pending-change review. Discover nested repos by + running `find server/modules -maxdepth 2 -name ".git" -type d` from the workspace root, + then for each discovered repo (and the top-level root) run `git diff --cached --name-only` + and `git diff --name-only`. Aggregate all results, filtering to applicable extensions + (`.tsx`, `.ts`, `.js`, `.jsx`, `.scss`, `.css`, `.jsp`, `.jspf`). + +- **Path provided (no `--full` flag -- default):** Determine the git root via + `git -C rev-parse --show-toplevel`. + - *File path:* Run `git diff --cached -- ` and `git diff -- `. If there are + no changes, report "No staged or working-tree changes found for ``." and stop. + If there are changes, proceed to review. + - *Directory path:* Run `git diff --cached --name-only -- ` and + `git diff --name-only -- `. Filter to applicable extensions. If no changed files + are found, report "No staged or working-tree changes found under ``." and stop. + +- **Path + `--full`:** Review the entire contents regardless of git status. + - *File path:* Use the file directly -- no git discovery needed. + - *Directory path:* Find all files matching applicable extensions under the directory + (using glob/find). Review every matching file. + +- **`--full` with no path:** Ask the user to provide a file or directory path. + +**Review scope when reviewing staged changes (default mode):** + +When reviewing staged changes, read the full file for context but **focus the review on changed +lines and their immediate surroundings**. Use the diff output to identify which sections +changed, then apply the checklist rules primarily to those sections. Still flag issues in +unchanged code only if they directly interact with or are affected by the changes. + +**Multi-file grouping:** When reviewing multiple files, group all findings together by urgency section (urgent issues first, then suggestions), not per-file. Include the file path in each finding's `FilePath` field. + +1. Open the relevant file(s). Gather all lines. +2. For each applicable checklist rule, evaluate the code against the rule text. +3. For each confirmed violation, capture evidence (exact snippet and/or file/line), record the WCAG criterion, and note confidence. +4. Compose the review per the template below. + +## Required output +When invoked, the response must exactly follow one of the two templates: + +### Template A (any findings) +``` +# Accessibility review (WCAG 2.2 AA) +Found urgent issues that need to be fixed: + +## 1 +FilePath: line +WCAG Criterion: +Evidence: +Confidence: - + + +### Suggested fix + + +--- +... (repeat for each urgent issue) ... + +Found suggestions for improvement: + +## 1 +FilePath: line +WCAG Criterion: +Evidence: +Confidence: - + + +### Suggested fix + + +--- + +... (repeat for each suggestion) ... +``` + +If there are no urgent issues, omit that section. If there are no suggestions, omit that section. + +Always list every urgent issue -- never cap or truncate them. If there are more than 10 suggestions, summarize as "10+ suggestions" and output the first 10. + +Don't compress the blank lines between sections; keep them as-is for readability. + +If you use Template A and at least one issue requires code changes, append a brief follow-up question after the structured output asking whether the user wants you to apply the suggested fix(es). + +### Template B (no issues) +``` +# Accessibility review (WCAG 2.2 AA) +No issues found. +``` diff --git a/.claude/skills/wcag-compliance/wcag-22-checklist.md b/.claude/skills/wcag-compliance/wcag-22-checklist.md new file mode 100644 index 0000000000..bdba73d77e --- /dev/null +++ b/.claude/skills/wcag-compliance/wcag-22-checklist.md @@ -0,0 +1,203 @@ +# WCAG 2.2 Level AA -- Static Code Review Checklist + +This checklist covers WCAG 2.2 Level AA success criteria that can be detected through code review. Criteria that require runtime testing (e.g., timing, audio descriptions) are excluded. + +--- + +## Principle 1: Perceivable + +### 1.1.1 Non-text Content (Level A) +**Urgency: urgent** +- `` elements must have an `alt` attribute. Decorative images should use `alt=""` or `role="presentation"`. +- Icon-only buttons/links must have an accessible name (`aria-label`, `aria-labelledby`, or visually hidden text). +- `` elements used as content must have `role="img"` and an accessible name (`aria-label` or ``). +- Font icon elements (e.g., ``, `
`, `
`, `