关于 accessibility-diff
accessibility-diff 是用于比较两个版本无障碍检查结果的技能,面向需要确认代码变更影响的开发者。它只报告新增、修复和既有问题,不直接编辑代码。
主要功能
- 01比较两个版本的检查结果
- 02报告新增、修复及既有问题
- 03提供问题位置与证据
- 04支持当前变更或分支对比
适用场景
- 01检查未提交代码是否引入无障碍问题
- 02比较分支与默认分支的结果
- 03定位新增问题以便后续修复
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ accesslint/ skills --skill accessibility-diff安装后在 Claude Code 中输入/accessibility-diff确认已加载。
详细介绍
默认分支:!git symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null | sed 's|.*/||' || echo main
仅报告变更内容。定位问题;不要修复。
共享的依据与诚实性约定:../shared/methodology.md。
解析 $ARGUMENTS:如果存在 --branch <name>,移除该参数并使用分支模式(未提供值时使用上述默认分支)。其余内容为目标:URL、配置目标名称;若为空,则使用 accesslint.config.json 中的默认目标。如果内容为空且没有配置,请询问 URL。
1. 审计
PORT=$(npx -y @accesslint/chrome@latest ensure | node -e 'process.stdin.on("data",d=>process.stdout.write(""+JSON.parse(d).port))')
暂存模式(默认;未提交的变更)。先告知用户:"正在以差异模式运行——暂存你的变更以捕获基线,然后恢复。你的工作树将完全恢复。" 如果 git stash push 失败,请发出警告并退出。
git stash push -u -m "accesslint-diff-baseline"
npx -y @accesslint/cli@latest scan <target> --port "$PORT" --snapshot accesslint-diff --snapshot-dir /tmp --update-snapshot
git stash pop && sleep 2
npx -y @accesslint/cli@latest scan <target> --port "$PORT" --snapshot accesslint-diff --snapshot-dir /tmp --format json
分支模式(--branch <name>)。先告知用户:"正在与 <name> 比较——切换到该分支以捕获基线,然后恢复。你的工作树将完全恢复。" 切换分支会触发重新构建,但不会重新加载浏览器,因此 CLI 每次运行都会打开一个新标签页来读取当前构建。使用 --wait-for "<selector>" 可让审计等待重新构建就绪;如果未使用,请警告用户:缓慢的构建可能会导致基线过时。
git diff --quiet && git diff --cached --quiet || git stash push -u -m "accesslint-diff-branch"
git checkout <branch>
npx -y @accesslint/cli@latest scan <target> --port "$PORT" --snapshot accesslint-diff --snapshot-dir /tmp --update-snapshot [--wait-for "<selector>"]
git checkout - && git stash pop 2>/dev/null
npx -y @accesslint/cli@latest scan <target> --port "$PORT" --snapshot accesslint-diff --snapshot-dir /tmp --format json [--wait-for "<selector>"]
两次运行都传入 --selector 和 --include-aaa。
2. 报告
Accessibility diff — http://localhost:3000/ vs main (94 rules, live DOM)
2 new · 1 fixed · 4 pre-existing hidden
New — Critical
- color-contrast — 2.1:1 (needs 4.5:1), #bbb on #fff
where: main > p.subtitle fix: darken to #767676
Fixed
- img-alt — <img src="old.jpg"> (no longer present)
对于每个新增违规项:提供位置(选择器原样照录;如果存在 source,还要提供 file:line (symbol),不要编造)、证据和修复方案(机械性变更或 NEEDS HUMAN)。
不要编辑。对于修复,应用机械性修复并重新运行 accesslint:accessibility-diff 进行验证;对于批量工作,请交由 accesslint:accessibility-fix 处理。
3. 收尾
npx -y @accesslint/chrome@latest stop --all # skip if ensure reported "managed":false
备注
- 端口由
ensure确定;不要将 9222 写死。 - CLI 退出码 2 表示 URL 或目标无效,或页面始终未加载;请检查开发服务器。
- 只有在暂存或检出期间
accesslint.config.json保持不变时,两次运行中的目标名称才会解析为同一目标。如果你的变更涉及配置,请传入明确的 URL。 - 暂存模式:
sleep 2可应对大多数 HMR 情况;如果基线看起来与当前状态相同,请添加--wait-for "<selector>"。 - 分支模式:不会触发 HMR;CLI 每次运行都会打开一个新标签页,而
--wait-for是重新构建的等待条件。 - 两次运行之间 DOM 发生大量变化会导致选择器漂移;请重新运行
accesslint:accessibility-scan以获取完整情况。