# @accesslint/cli 中文文档

规范地址：https://npmcn.com/package/%40accesslint/cli/

版本：0\.13\.0
npm 元数据更新时间：2026-08-22T21:33:17.974Z
中文译文更新时间：2026-11-06T00:44:54.589Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40accesslint/cli
原文对照：https://npmcn.com/package/%40accesslint/cli/?lang=original
项目主页：https://github.com/AccessLint/accesslint#readme
源码仓库：https://github.com/AccessLint/accesslint

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：200 kB，10 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：3 个
- 首次发布：2026-02-24T02:02:42.526Z
- 最新版本发布：2026-08-22T21:33:17.655Z
- 近 30 天下载量：7917（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：27（近 12 个月 27 个）

## 中文简介

使用 @ accesslint/ core 来审计 HTML 访问的 CLI 工具

## 安装

```sh
npm install @accesslint/cli
```

也可以使用：`pnpm add @accesslint/cli`、`yarn add @accesslint/cli`、`bun add @accesslint/cli`

## README

# @ accesslint/ cli (英语)

使用 CLI 来审计 HTML 访问工具 [@ accesslint/ 核心](https://github.com/AccessLint/accesslint/tree/main/core)。 。 。 .

```sh
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` ——审计

### 来源

```bash
# 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个 | 错误 |

### 实例

```bash
# 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` 脚手架配置

```bash
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在发现时被预填.

```jsonc
// 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)
```

## 常见问题

### @accesslint/cli 是什么？

使用 @ accesslint/ core 来审计 HTML 访问的 CLI 工具

### 如何安装 @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 和提交记录判断。

