@accesslint/cli

中文文档
0.13.0发布于 2026/08/23MITES Module构建来源已验证近 30 天下载 7917

CLI tool for auditing HTML accessibility using @accesslint/core

原始使用文档
文档目录6 节
  1. scan — audit
  2. Sources
  3. Options
  4. Exit codes
  5. Examples
  6. init — scaffold config

@accesslint/cli

CLI tool for auditing HTML accessibility using @accesslint/core.

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 — breaking change. The audit now lives under the scan subcommand: run accesslint scan <source> (previously accesslint <source>).

scan — audit

Sources

# 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

A non-URL, non-file argument is resolved as a target name from accesslint.config.json (the local overlay takes precedence), expanding to that target's url and options; explicit flags override the target's. With no argument, the config's default target is audited. An unknown name lists the available targets. To pipe HTML in a project that has a config, pass --stdin.

Options

-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 audits connect to a debuggable Chrome over CDP. Start one with npx @accesslint/chrome ensure, then pass the port if it differs from the default.

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

Exit codes

CodeMeaning
0No violations
1Violations found
2Error

Examples

# 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 — scaffold config

npx -y @accesslint/cli init        # interactive, framework-aware defaults
npx -y @accesslint/cli init --yes  # accept the defaults (CI / non-interactive)

Writes accesslint.config.json with named audit targets, plus a gitignored accesslint.config.local.json overlay for prod/staging. Defaults are inferred from your package.json: the framework sets the dev port (an explicit -p/--port in the dev script wins). No port scanning. A Storybook target is not added by default — pass --storybook (or opt in at the prompt when Storybook is detected); its URL is pre-filled when found.

// accesslint.config.json
{
  "default": "dev",
  "targets": {
    "dev": { "url": "http://localhost:5173" },
    "storybook": { "url": "http://localhost:6006" },
  },
}

Each target carries the same options as scan flags (url, selector, waitFor, includeAAA, disable, snapshotDir), so a target is a fully-specified audit context.

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

版本与发布记录

@accesslint/cli 共发布 27 个版本,首次发布于 2026/02/24;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.13.0latest2026/08/232 个月前
0.12.02026/07/213 个月前
0.11.12026/07/213 个月前
0.11.02026/07/203 个月前
0.10.02026/06/055 个月前
0.9.02026/06/045 个月前

关于 @accesslint/cli 的常见问题

@accesslint/cli 是什么?

CLI tool for auditing HTML accessibility using @accesslint/core

如何安装 @accesslint/cli?

在项目目录运行 npm install @accesslint/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 accesslint,可以用 npx accesslint 直接运行。

@accesslint/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/accesslint__cli 是否存在。

@accesslint/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@accesslint/cli 可以商用吗?

@accesslint/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@accesslint/cli 的下载量有多少?

根据 npm 官方下载统计,@accesslint/cli 在 2026/10/05 – 2026/11/03 这 30 天内被下载 7,917 次,日均约 264 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@accesslint/cli 还在维护吗?

最新版本 0.13.0 发布于 2026/08/23(2 个月前);至今共发布 27 个版本,其中过去 12 个月发布了 27 个;首次发布于 2026/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。