@ accesslint/ cli (英语)
使用 CLI 来审计 HTML 访问工具 @ accesslint/ 核心。 。 。 .
npx -y @accesslint/cli scan [source] [options] # audit a URL, HTML file, or stdin
npx -y @accesslint/cli init # scaffold accesslint.config.json
v0.8 — 突破变化. 审计现以
scan子命令 : 运行accesslint scan <source>(先前为accesslint <source>) (中文(简体) ).
scan ——审计
来源
# Audit a local file
npx -y @accesslint/cli scan index.html
# Audit a URL (requires a debuggable Chrome; start one first)
npx @accesslint/chrome ensure
npx -y @accesslint/cli scan https://example.com
# Pipe HTML via stdin
curl -s https://example.com | npx -y @accesslint/cli scan
# Audit a named target from accesslint.config.json (see `init` below)
npx -y @accesslint/cli scan dev
非URL、非文件论证作为 目标名称 从 accesslint.config.json
(地方重叠优先),扩大到目标 url 和选项; 明确
旗帜覆盖目标。 与 没有 参数,配置 default 目标被审计。 一个
未知名称列出可用的目标 。 在有配置的工程中管道 HTML, 通过
--stdin。 。 。 .
选项
-f, --format <fmt> Output format: text, json, sarif (default: text)
--pretty Pretty-print json/sarif output (default: single line)
--include-aaa Include AAA-level rules
-d, --disable <ids> Comma-separated rule IDs to disable
-h, --help Show help
--version Show version
URL审计连接到 CDP 上的可调试的 Chrome. 开始一个
npx @accesslint/chrome ensure,然后通过与默认不同的端口.
-p, --port <n> CDP port (URL audits only, default: 9222)
--host <host> CDP host (URL audits only, default: 127.0.0.1)
-s, --selector <sel> CSS selector to scope the audit; auto-waits for element (URL only)
--wait-for <s> Selector or visible text to wait for before auditing (URL only)
--wait-timeout <ms> Max ms to wait for --wait-for or --selector (default: 10000)
--attach Only attach to an existing tab matching the URL; fail if not found
--snapshot <name> Snapshot name — fail only on violations new since baseline (URL only)
--snapshot-dir <dir> Directory for snapshot files (default: ./accessibility-snapshots)
--update-snapshot Force-overwrite the snapshot baseline (also: ACCESSLINT_UPDATE=1)
退出代码
| 代码 | 含义 |
|---|---|
| 0 个 | 无违反规定行为 |
| 1个 | 查明的侵犯行为 |
| 2个 | 错误 |
实例
# Text output with colors
echo '<img src="photo.jpg">' | npx -y @accesslint/cli scan
# JSON output
npx -y @accesslint/cli scan --format json index.html
# SARIF for GitHub code scanning (upload via github/codeql-action/upload-sarif)
npx -y @accesslint/cli scan --format sarif https://localhost:3000 > accesslint.sarif
# Audit a fragment — page-level rules (document-title, html-has-lang) are skipped automatically
echo '<button></button>' | npx -y @accesslint/cli scan
# Disable specific rules
npx -y @accesslint/cli scan -d "landmarks/region,navigable/bypass" index.html
# Snapshot mode — capture a baseline; fail only on new violations
npx -y @accesslint/cli scan --snapshot main https://example.com
init 脚手架配置
npx -y @accesslint/cli init # interactive, framework-aware defaults
npx -y @accesslint/cli init --yes # accept the defaults (CI / non-interactive)
写作 accesslint.config.json 审计名称 目标,加一个被点缀
accesslint.config.local.json 叠接/粘接。 默认从您的
package.json: 框架设置了 dev 端口(一个明确的 -p编号 :--port 输入 dev 脚本
) (中文(简体). 没有端口扫描 。 故事书目标 没有 默认添加-通过 --storybook
(或在检测到"故事本"时在提示时选择加入);其URL在发现时被预填.
// accesslint.config.json
{
"default": "dev",
"targets": {
"dev": { "url": "http://localhost:5173" },
"storybook": { "url": "http://localhost:6006" },
},
}
每一个目标都带有与 scan 旗帜(url, (中文(简体) ), selector, (中文(简体) ), waitFor, (中文(简体) ),
includeAAA, (中文(简体) ), disable, (中文(简体) ), snapshotDir因此,目标是一个充分具体的审计背景.
-y, --yes Accept framework-aware defaults without prompting
--dev-url <url> Override the inferred dev URL
--storybook Add a Storybook target
--skip-storybook Do not add a Storybook target
--prod-url <url> Prod/staging URL (written to the gitignored overlay)
--default <name> Name of the default target (default: dev)
--force Overwrite an existing accesslint.config.json
--cwd <dir> Project directory (default: current directory)