# @coderrob/eslint-plugin-zero-tolerance 中文文档

规范地址：https://npmcn.com/package/%40coderrob/eslint-plugin-zero-tolerance/

版本：1\.2\.9
npm 元数据更新时间：2026-11-05T22:44:20.207Z
中文译文更新时间：2026-11-10T07:45:43.695Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40coderrob/eslint-plugin-zero-tolerance
原文对照：https://npmcn.com/package/%40coderrob/eslint-plugin-zero-tolerance/?lang=original
项目主页：https://github.com/Coderrob/eslint-config-zero-tolerance/
源码仓库：https://github.com/Coderrob/eslint-config-zero-tolerance

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

- 包体积（解压后）：398 kB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.18\.0
- 运行依赖：1 个
- peer 依赖：eslint ^8\.57\.0 \|\| ^9\.0\.0 \|\| ^10\.0\.0，typescript ^5\.0\.0，@typescript-eslint/parser ^8\.0\.0
- 首次发布：2026-03-06T06:00:48.955Z
- 最新版本发布：2026-11-05T22:44:19.870Z
- 近 30 天下载量：4437（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 20 个）

## 中文简介

严格,有意见的ESLint规则为TypeScript——执行类型安全,代码质量,测试标准,以及零例外的可维护模式.

## 安装

```sh
npm install @coderrob/eslint-plugin-zero-tolerance
```

也可以使用：`pnpm add @coderrob/eslint-plugin-zero-tolerance`、`yarn add @coderrob/eslint-plugin-zero-tolerance`、`bun add @coderrob/eslint-plugin-zero-tolerance`

## README

# @coderrob/eslint-plugin-零容忍

[无魔法数](https://coderrob.github.io/eslint-config-zero-tolerance/rules/no-magic-numbers/) 允许在命名常数中进行算术,例如 `const SOMETHING = 10 * 100;`。 。 。 .

[行为安全合同](https://npmcn.com/package/docs/rule-fix-safety.md) 记录正负输入、参数边界、状态隔离和需要人工迁移的情况.

规则套房需要非空有效而无效的固定装置,命名为 `should` 病例、明确的诊断和混凝土自动固定输出。 所有83个规则也都与共享的TypeScript,JSX,可选访问,以及捷克链剖析固定装置相对抗. 见 [贡献指南](https://npmcn.com/package/CONTRIBUTING.md) 用于验证要求.

严格,有意见的ESLint插件用于TypeScript,执行类型安全,代码质量,测试标准,以及可维护的模式——除零例外.

[![npm version](https://img.shields.io/npm/v/@coderrob/eslint-plugin-zero-tolerance.svg)](https://www.npmjs.com/package/@coderrob/eslint-plugin-zero-tolerance) [![License](https://img.shields.io/npm/l/@coderrob/eslint-plugin-zero-tolerance.svg)](https://github.com/Coderrob/eslint-config-zero-tolerance/blob/main/LICENSE)

## 特征

-   **83个定制ESLint规则** 包括8个类别:类型安全、代码质量、测试、进口、错误处理、防虫、命名公约和文件
-   **两个预设** —— 说 `recommended` 通常采用警告严重性来逐步收养,同时 `strict` 一般使用出错严重性;以下列出严格例外和选入例外
-   **ESLint 8.57+, 9.x,和 10.x** ——平面布局和遗产 `.eslintrc` 两者均获得支持
-   **99xx测试覆盖率** ——每条规则都通过有效案件和无效案件进行彻底检验
-   与 `@typescript-eslint/utils` 用于完整类型脚本 AST 支持

## 所需资源

-   节点.js
    -   18.1.8.0+ 当使用ESLint 8.5.7.0+或9.x时
    -   20.19.0+, 22.13.0+,或 24.0.0+ 当使用ESLint 10.x时
    -   经测试的LTS释放:18.20.8、20.20.2、22.23.4、24.22.2和26.13.0
-   ESLint 8.57.0+, 9.x, 或 10.x
    -   CI测试的主要释放:8.57.1、9.39.5和10.14.0
-   `@typescript-eslint/parser` 8.x 电话
-   类型脚本 5.x

## 安装

```bash
npm install --save-dev @coderrob/eslint-plugin-zero-tolerance @typescript-eslint/parser
```

## 快速启动

### ESLint 9+ (Flat Config) (中文(简体) )

```javascript
// eslint.config.js
import zeroTolerance from '@coderrob/eslint-plugin-zero-tolerance';

export default [zeroTolerance.configs.recommended];
```

### ESLint 8.x (法语:Legacy Config)

```javascript
// .eslintrc.js
module.exports = {
  plugins: ['@coderrob/zero-tolerance'],
  extends: ['plugin:@coderrob/zero-tolerance/legacy-recommended'],
};
```

遗留 ESLint 通过 `@coderrob/zero-tolerance` 简称,所以 手动选择遗留规则 ID 使用 `@coderrob/zero-tolerance/<rule-name>`。平面配置继续 用于使用 `zero-tolerance` 以下显示名称空间 .

### 自定义规则选择

```javascript
// eslint.config.js
import zeroTolerance from '@coderrob/eslint-plugin-zero-tolerance';

export default [
  {
    plugins: {
      'zero-tolerance': zeroTolerance,
    },
    rules: {
      'zero-tolerance/require-interface-prefix': 'error',
      'zero-tolerance/no-throw-literal': 'error',
      'zero-tolerance/max-function-lines': ['warn', { max: 40 }],
    },
  },
];
```

## 预设

| 预设 | 严重性 | 配置密钥 |
| --- | --- | --- |
| 建议 | `warn` | `configs.recommended` |
| 严格 | `error` | `configs.strict` |
| 建议的遗产 | `warn` | `legacy-recommended` |
| 严格遗产 | `error` | `legacy-strict` |

预设断裂描述启用规则的默认值 . `prefer-result-return` 严格,而 `require-bdd-spec`, (中文(简体) ), `require-jsdoc-anonymous-functions`, (中文(简体) ), `no-fetch-in-tests`, (中文(简体) ), `no-parent-internal-access`,以及 `no-restricted-imports-in-tests` 继续选择两个预设。 见 [完整规则文档](https://coderrob.github.io/eslint-config-zero-tolerance/rules/) 每个规则的预设状态.

## 规则

### 命名公约

| 规则 | 说明 |
| --- | --- |
| `require-interface-prefix` | 执行 TypeScript 界面名称的起始 `I` 然后是大写字母 |

### 文档

| 规则 | 说明 |
| --- | --- |
| `require-bdd-spec` | 强制执行每个 TypeScript 源文件都有有效的兄弟姐妹.ts.bdd.json BDD spec |
| `require-jsdoc-anonymous-functions` | 要求 JSDoc 除了测试文件和已知的测试回调之外, 对匿名函数类构造的评论 |
| `require-jsdoc-functions` | 要求 JSDoc 对命名函数的评论(测试文件除外) |
| `require-optional-chaining` | 报告重复的逻辑保护访问,供手工审查 |
| `require-readonly-props` | 要求 JSX 组件道具作为只读键输入 |

### 测试

| 规则 | 说明 |
| --- | --- |
| `require-test-description-style` | 执行测试描述从 `should` |
| `no-chai-imprecise-spy-assertions` | 需要精确的柴式间谍呼叫数和引用论据 |
| `no-conditional-test-assertion` | 在测试分支中否定无法执行的断言 |
| `no-jest-have-been-called` | 在 Jest 断言中要求精确的呼叫数和引用指数;允许否定的零呼叫检查 |
| `no-mock-implementation` | 禁止持久性模拟方法;使用 `Once` 防止测试出血的变体 |
| `no-sinon-imprecise-spy-assertions` | 需要准确的Sinon间谍通话数和引用论据 |
| `no-set-timeout-in-tests` | 否定 `setTimeout` 测试文件中的使用 |
| `no-set-interval-in-tests` | 否定 `setInterval` 测试文件中的使用 |
| `no-fetch-in-tests` | 否定 `fetch` 测试文件中的使用 |
| `no-restricted-imports-in-tests` | 取消测试文件中配置的依赖性导入 |
| `no-test-interface-declaration` | 在测试文件中取消接口声明; 改为导入生产类型 |
| `no-unawaited-async-assertion` | 要求同步测试断言等待或返回 |
| `no-vitest-imprecise-spy-assertions` | 需要精确的Vitest间谍电话数和引用指数 |

### 类型安全

| 规则 | 说明 |
| --- | --- |
| `no-type-assertion` | 防止使用类型脚本 `as` 和角-括号断言 |
| `no-non-null-assertion` | 使用 `!` 后缀运算符 |
| `no-explicit-any` | 明确否定 `any`;需要精确的建模或明确缩小范围 |
| `no-indexed-access-types` | 删除类型Script索引访问类型 |
| `no-literal-unions` | 报告人工迁移到矿井的文字结合 |
| `no-literal-property-unions` | 要求属性字面结合使用命名域类型 |
| `require-union-type-alias` | 需要包含多个类型引用的内置联盟类型以使用命名类型别名 |
| `no-inline-type-import` | 淡出内线 `import("...").Type` 说明 |
| `no-return-type` | 丢弃类型脚本 `ReturnType` 公用事业使用情况 |
| `no-destructured-parameter-type-literal` | 解结构参数上的内线对象类型 |
| `require-exported-object-type` | 要求导出对象常数声明明确类型的注释 |
| `no-unsafe-json-parse` | 拒绝将 JSON.parse 结果作为未验证而输入的数据 |

### 代码质量

| 规则 | 说明 |
| --- | --- |
| `max-function-lines` | 每个函数体执行最大行数 |
| `max-params` | 执行最大函数参数 |
| `no-array-mutation` | 取消变异数组方法 |
| `no-date-now` | 否定 `Date.now()` 和无鼠标 `new Date()` 使用量 |
| `no-placeholder-implementation` | 取消占位符、分贝、TODO和未执行的生产代码 |
| `no-magic-numbers` | 取消魔法数; 使用命名常数代替 |
| `no-magic-strings` | 在比较和切换时取消魔法字符串 |
| `no-map-set-mutation` | 拒绝直接 `Map` 财务报告和审定财务报表 `Set` 变异方法 |
| `no-object-mutation` | 直接对象属性变异 |
| `sort-imports` | 在保存运行时依赖命令时报告导入命令 |
| `sort-functions` | 需要按字母排序顶级函数和康斯特函数表达式 |
| `prefer-nullish-coalescing` | 偏好为本地绑定的标识标记三角形进行无效组合 |
| `prefer-object-spread` | 报告空目标对象。 在使用对象扩展前, 指定人工审查的调用 |
| `prefer-readonly-parameters` | 对象和类似数组参数优先只读打入 |
| `prefer-string-raw` | 首选本土 `String.raw` 当建造者没有被阴影的时候 |
| `prefer-structured-clone` | 在考虑结构化Clone(.)之前审查 JSON.parse(JSON.stringify (.)) |

### 处理错误

| 规则 | 说明 |
| --- | --- |
| `no-empty-catch` | 取消空捕捉块, 静静地吞下错误 |
| `no-throw-literal` | 拒绝丢弃文字、对象或模板; 总是丢出新的 `Error` 实例 |
| `prefer-result-return` | 偏好返回结果样式的值而不是抛出 |

### 进口

`no-parent-internal-access` 仍然选择使用,并且只匹配在 `..` 横行,例如 `../src/foo`。 。 。 .

| 规则 | 说明 |
| --- | --- |
| `require-clean-barrel` | 需要枪管文件( E)`index.*`)只包含模块再导出 |
| `require-barrel-relative-exports` | 要求再出口桶使用 `./` 后人路径 |
| `no-barrel-parent-imports` | 在枪管文件导入路径中取消父目录转录 |
| `no-parent-internal-access` | 不允许父目录和亲目录连接到受保护的内部目录, 如 `src` |
| `no-dynamic-import` | 禁用动态 `import()` 财务报告和审定财务报表 `require()` 外部测试文件 |
| `no-export-alias` | 防止在出口报表中使用别名 |
| `no-hardcoded-secrets` | 否认硬码密件、证书、信使和密件默认 |
| `no-raw-sql-interpolation` | 拒绝插入原始 SQL 和不安全的原始查询助手 |
| `no-re-export` | 从父母/祖父母模块取消直接出口或通过再出口 |
| `no-shell-command-construction` | 通过子进程 API 取消 shell 命令构建 |
| `no-unsafe-code-generation` | Disallow eval, 函数构造器, 字符串定时器, 以及 vm 执行 APIs |
| `require-node-protocol` | 需要节点.js内置模块导入以使用 `node:` 协议前缀 |

### 防止错误

| 规则 | 说明 |
| --- | --- |
| `no-identical-expressions` | 在二进制或逻辑运算符的两侧取消相同的表达式 |
| `no-identical-branches` | 取消相同的条件分支 |
| `no-boolean-return-trap` | 取消上游命名以外的模糊布尔返回 API |
| `no-redundant-boolean` | 仅在已知操作为布尔时简化比较 |
| `no-for-in` | 在不重写继承的密钥行为的循环中, 拒绝.. |
| `no-labels` | 取消标签的语句 |
| `no-with` | 否定 `with` 声明 |
| `no-await-in-loop` | 否定 `await` 内环; 使用 `Promise.all()` 换成 |
| `no-floating-promises` | 请检查url=值 (帮助) |
| `no-math-random` | 否定 `Math.random()`; 转而插入随机源 |
| `no-eslint-disable` | 防止使用 `eslint-disable` 评论 |
| `no-parameter-reassign` | 取消重新指定函数参数 |
| `no-process-env-outside-config` | 否定 `process.env` 读取外部配置模块 |
| `no-flag-argument` | 函数签名中的布尔旗参数 |
| `prefer-guard-clauses` | 如果分支终止,则删除其他块,从而优先适用保护条款 |
| `prefer-shortcut-return` | 在保留注释的同时简化布尔返回 |
| `no-query-side-effects` | 在查询样式函数中消除副作用 |
| `require-timeout-for-io` | 外部 IO 呼叫需要超时或取消选项 |
| `require-exhaustive-switch` | 需要详尽 `switch` 限定性歧视类型的声明 |

## 文档

附有实例的完整规则文件,见:

[https://coderrob.github.io/eslint-config-0-容忍主义/](https://coderrob.github.io/eslint-config-zero-tolerance/)

## 选择检查

使用 [规则参考](https://npmcn.com/package/docs/rules/index.md) 以选择检查和审查实例、选项和限制。 启用 [需要 - 错误 - 因为](https://npmcn.com/package/docs/rules/require-error-cause.md) 单独保留原有例外.

关于承诺处理、不安全类型、回调和分支限制,参见 [额外编码质量检查](https://npmcn.com/package/docs/configuration.md#additional-code-quality-checks-individual-opt-in)。 。 。 .

## 许可证

[Apache 2.0 (英语)](https://github.com/Coderrob/eslint-config-zero-tolerance/blob/main/LICENSE) 版权:罗伯特·林德利

## 常见问题

### @coderrob/eslint-plugin-zero-tolerance 是什么？

严格,有意见的ESLint规则为TypeScript——执行类型安全,代码质量,测试标准,以及零例外的可维护模式\.

### 如何安装 @coderrob/eslint-plugin-zero-tolerance？

在项目目录运行 npm install @coderrob/eslint-plugin-zero-tolerance，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：eslint（^8\.57\.0 \|\| ^9\.0\.0 \|\| ^10\.0\.0）、typescript（^5\.0\.0）、@typescript-eslint/parser（^8\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @coderrob/eslint-plugin-zero-tolerance 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @coderrob/eslint-plugin-zero-tolerance 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @coderrob/eslint-plugin-zero-tolerance 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18\.18\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @coderrob/eslint-plugin-zero-tolerance 可以商用吗？

@coderrob/eslint-plugin-zero-tolerance 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @coderrob/eslint-plugin-zero-tolerance 的下载量有多少？

根据 npm 官方下载统计，@coderrob/eslint-plugin-zero-tolerance 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,437 次，日均约 148 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @coderrob/eslint-plugin-zero-tolerance 还在维护吗？

最新版本 1\.2\.9 发布于 2026/11/06（4 天前）；至今共发布 20 个版本，其中过去 12 个月发布了 20 个；首次发布于 2026/03/06。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

