# @darraghor/eslint-plugin-nestjs-typed 中文文档

规范地址：https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/

版本：7\.5\.8
npm 元数据更新时间：2026-10-05T07:50:54.690Z
中文译文更新时间：2026-11-11T12:10:24.059Z
软件包许可：ISC

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

原始 npm 页面：https://www.npmjs.com/package/%40darraghor/eslint-plugin-nestjs-typed
原文对照：https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/?lang=original
项目主页：https://github.com/darraghoriordan/eslint-plugin-nestjs-typed
源码仓库：https://github.com/darraghoriordan/eslint-plugin-nestjs-typed

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

- 包体积（解压后）：352 kB，100 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=24\.0\.0
- 运行依赖：7 个
- peer 依赖：eslint \>=9\.18\.0，class-validator \*，@typescript-eslint/parser ^7\.0\.0 \|\| ^8\.0\.0
- 首次发布：2021-06-04T14:41:35.801Z
- 最新版本发布：2026-10-05T07:50:54.334Z
- 近 30 天下载量：1127674（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：315（近 12 个月 88 个）

## 中文简介

Eslint 巢项目的规则

## 安装

```sh
npm install @darraghor/eslint-plugin-nestjs-typed
```

也可以使用：`pnpm add @darraghor/eslint-plugin-nestjs-typed`、`yarn add @darraghor/eslint-plugin-nestjs-typed`、`bun add @darraghor/eslint-plugin-nestjs-typed`

## README

![commit](https://badgen.net/github/last-commit/darraghoriordan/eslint-plugin-nestjs-typed/main) ![npm](https://img.shields.io/npm/v/@darraghor/eslint-plugin-nestjs-typed.svg?color=red) ![npm-tag](https://badgen.net/github/tag/darraghoriordan/eslint-plugin-nestjs-typed) ![size](https://badgen.net/bundlephobia/minzip/@darraghor/eslint-plugin-nestjs-typed?color=cyan) ![types](https://badgen.net/npm/types/@darraghor/eslint-plugin-nestjs-typed?color=blue)

# 雀巢JS Eslint 插件

如果使用 NestJs (则[https://nestjs.com/ (中文(简体) )](https://nestjs.com/)这些 ESLint 规则将帮助您防止 NestJs 应用程序中的常见错误和问题.

跳转到 [如何配置](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/#readme-to-configure) 但是如果你有问题 回来阅读整个文件.

```
pnpm add -D @darraghor/eslint-plugin-nestjs-typed
//or
npm i -D @darraghor/eslint-plugin-nestjs-typed
//or
bun install -d @darraghor/eslint-plugin-nestjs-typed
```

## 支持此插件

如果您在商业环境中使用此插件, 考虑在工作时间提交 PR 。 它能节省你的生意钱 所以它能赚你的生意钱!

如果你真的想直接支持我 你可以用 [https://darraghoriordan.gumroad.com/coffee (中文(简体) )](https://darraghoriordan.gumroad.com/coffee)

但请提交公关 帮助所有的NestJS devs。 这是路!

## 关于版本的说明

-   版本 `6.x` 支持 Eslint 版本 `^9` 和打字机 eslint 解析器 `^7` 财务报告和审定财务报表 `^8`
-   版本 `5.x` 支持 Eslint 版本 `^8` 和打字机 eslint 解析器 `^7` 财务报告和审定财务报表 `^8`
-   版本 `4.x` 支持 Eslint 版本 `^8` 和打字机 eslint 解析器 `^6`
-   版本 `3.x` 支持 Eslint 版本 `^8` 和打字机 eslint 解析器 `^5`
-   版本 `2.x` 支持 Eslint 版本 `^7.x` 和打字机 eslint 解析器 `^4`

## Eslint 9.x 支持

我已经更新了配置 与eslint 9.x合作。 这是一个突破性的变化.

如果您正在使用 eslint 8. x, 您应该使用此插件的 5. x 版本 .

我试图把旧风格的配置留在原地 但我还没有对其进行适当的测试 如果有任何问题,请提交公关.

见 [如何配置](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/#readme-to-configure) 需要更多信息.

## TS Eslint 版本支持

Ts-slint的版本之间有断裂变化.

typescript eslint parser支持一系列的打字版本,但支持最新版本可能会有延迟.

此插件只支持至版本的打字符 eslint 剖析器支持 。 见 [https://github.com/typescript-eslint/typescript-eslint#被支持的-typescript-version 互联网档案馆的存檔,存档日期2013-12-11](https://github.com/typescript-eslint/typescript-eslint#supported-typescript-version) 对版本.

## 有规则吗?

请提交拉力请求 见 [捐款](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/CONTRIBUTING.md)。 。 。 .

## 现有规则索引

| 类别 | 规则 | 是在推荐规则? |
| --- | --- | --- |
| 巢穴模块和依赖性注射 | [`provided-injected-should-match-factory-parameters`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/provided-injected-should-match-factory-parameters.md) | ✅ |
|  | [`injectable-should-be-provided`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/injectable-should-be-provided.md) | ✅ |
|  | [`use-injectable-provided-token`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/use-injectable-provided-token.md) | ✅ |
|  | [`use-dependency-injection`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/use-dependency-injection.md) | ❌ |
|  |  |  |
| 巢斯瓦格岛 | [`api-property-matches-property-optionality`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-property-matches-property-optionality.md) | ✅ |
|  | [`controllers-should-supply-api-tags`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/controllers-should-supply-api-tags.md) | ✅ |
|  | [`api-method-should-specify-api-response`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-method-should-specify-api-response.md) | ✅ |
|  | [`api-method-should-specify-api-operation`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-method-should-specify-api-operation.md) | ❌ |
|  | [`api-enum-property-best-practices`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-enum-property-best-practices.md) | ✅ |
|  | [`api-property-returning-array-should-set-array`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-property-returning-array-should-set-array.md) | ✅ |
|  | [`api-property-should-have-api-extra-models`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-property-should-have-api-extra-models.md) | ✅ |
|  | [`api-operation-summary-description-capitalized`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-operation-summary-description-capitalized.md) | ✅ |
|  | [`swagger-file-upload-should-be-documented`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/swagger-file-upload-should-be-documented.md) | ✅ |
|  |  |  |
| 防止错误 | [`param-decorator-name-matches-route-param`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/param-decorator-name-matches-route-param.md) | ✅ |
|  | [`forward-ref-injection-should-use-wrapper-type`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/forward-ref-injection-should-use-wrapper-type.md) | ✅ |
|  | [`uploaded-file-should-be-validated`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/uploaded-file-should-be-validated.md) | ✅ |
|  | [`validate-nested-of-array-should-set-each`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/validate-nested-of-array-should-set-each.md) | ✅ |
|  | [`validated-non-primitive-property-needs-type-decorator`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/validated-non-primitive-property-needs-type-decorator.md) | ✅ |
|  | [`all-properties-are-whitelisted`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/all-properties-are-whitelisted.md) | ✅ |
|  | [`all-properties-have-explicit-defined`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/all-properties-have-explicit-defined.md) | ✅ |
|  | [`no-duplicate-decorators`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/no-duplicate-decorators.md) | ✅ |
|  | [`validation-pipe-should-use-forbid-unknown`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/validation-pipe-should-use-forbid-unknown.md) | ✅ |
|  |  |  |
| 警卫 | [`api-methods-should-be-guarded`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/api-methods-should-be-guarded.md) | ❌ |
|  |  |  |
| 代码一致性 | [`sort-module-metadata-arrays`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/sort-module-metadata-arrays.md) | ❌ |
|  | [`use-correct-endpoint-naming-convention`](https://npmcn.com/package/%40darraghor/eslint-plugin-nestjs-typed/src/docs/rules/use-correct-endpoint-naming-convention.md) | ❌ |

“建议”规则是配置此文档所描述的插件时打开的默认规则.

"推荐"这个名字是埃斯林特会,你可以安全地使用该列表中没有的规则,它们只是更有观点.

## 这个包裹是给谁用的?

如果使用 NestJs (则[https://nestjs.com/ (中文(简体) )](https://nestjs.com/)这些 ESLint 规则将帮助您防止 NestJs 应用程序中的常见错误和问题.

他们大多会检查你是否正确使用装饰器.

此插件中主要的规则分组是...

### 1\. 检测巢穴依赖性注射问题

巢穴DI是声明性的,如果你忘了提供注射器,在运行时间之前不会看到出错. 巢穴很会告诉你这些在哪里 但有时不是.

特别是如果你使用自定义的提供者 错误可能非常难解 因为他们不会明确错误 关于不匹配的注射项目, 你会得到意外的操作.

这些在"巢js docs"的"共同错误"一节中被描述.

### 2\. 使用 Open Api / Swagger 装饰并自动生成客户端

在与 NestJS 合作时,我使用由巢控制器和模型直接生成的 swagger/ Open API 规格生成我的前端客户端和模型.

我这里有一大堆规则 执行严格的开放 API打字 与装饰器 雀巢控制器和模型.

这些规则是有观点的,但对于清洁的模型生成来说是必要的,如果稍后在您的构建中使用了Open Api客户端生成器.

### 3\. 帮助预防错误

在巢穴里有一些紧密相接但无型的装饰器 和类似的东西 如果你不小心就会被抓住 有一些规则可以帮助防止我以前遇到的问题.

### 4\. 警卫

当使用随机的javascript对象时, CVE 用于类转换器 。 要注意在巢穴配置验证Pipe. 见 [https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-18413 (英语)](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-18413) [https://github.com/typestack/class-validator/issues/438 (中文(简体) )](https://github.com/typestack/class-validator/issues/438)

## 要安装

插件在 npm 这里: https://www.npmjs.com/package/@darraghor/eslint-plugin-nestjs-typed 您可以在 NestJS 项目中看到规则的使用: [https://github.com/darraghoriordan/use-miller 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/darraghoriordan/use-miller)

```
npm install --save-dev @darraghor/eslint-plugin-nestjs-typed

// or

yarn add -D @darraghor/eslint-plugin-nestjs-typed
// or

pnpm add -D @darraghor/eslint-plugin-nestjs-typed
```

如果你还没有 `class-validator` 你应该安装它

```
npm install class-validator

// or

yarn add class-validator

// or

pnpm add class-validator
```

## 要配置

更新您的平面 Eslint 配置, 导入插件并添加平面推荐规则集 .

我的配置是这样的 我百分之九十九确定你也要设置打字机.

```ts
import eslintNestJs from "@darraghor/eslint-plugin-nestjs-typed";
// ... and all your other imports
export default tseslint.config(
    eslint.configs.recommended,
    tseslint.configs.strictTypeChecked,
    tseslint.configs.stylisticTypeChecked,
    {
        languageOptions: {
            globals: {
                ...globals.node,
                ...globals.jest,
            },
            parser,
            ecmaVersion: 2022,
            sourceType: "module",
            parserOptions: {
                projectService: true,
                tsconfigRootDir: import.meta.dirname,
            },
        },
    },
    eslintNestJs.configs.flatRecommended // This is the recommended ruleset for this plugin
);
```

对于ESlint 8,我导出"经典Config"导出中的旧风格配置.

我相信这样会有用的...

```ts
import {classicPlugin} from "@darraghor/eslint-plugin-nestjs-typed";

module.exports = {
    plugins: [classicPlugin],
};
```

## 注射器可以扫描所有东西

注意:注射器测试扫描您的整个项目。 最好把无关紧要的东西过滤掉 - 使用 `filterFromPaths` 此配置设置 。 更多信息见规则文档.

已经应用了一些合理的默认.

注意:如果不通过添加 swagger 来关闭所有 swagger 规则,则可以轻松关闭 `flatNoSwagger` 规则设置在推荐的规则集之后.

```ts
// all the other config
    extends: [
       "plugin:@darraghor/nestjs-typed/recommended",
       "plugin:@darraghor/nestjs-typed/no-swagger"
    ],
 // more config
```

## 解除规则

禁用一个全名规则, 例如您在 eslint 配置中...

```ts
   rules: {
   "@darraghor/nestjs-typed/api-property-returning-array-should-set-array":
            "off",
   }
```

## 常见问题

### @darraghor/eslint-plugin-nestjs-typed 是什么？

Eslint 巢项目的规则

### 如何安装 @darraghor/eslint-plugin-nestjs-typed？

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

### @darraghor/eslint-plugin-nestjs-typed 支持 TypeScript 吗？

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

### @darraghor/eslint-plugin-nestjs-typed 支持 ESM 还是 CommonJS？

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

### @darraghor/eslint-plugin-nestjs-typed 需要什么版本的 Node\.js？

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

### @darraghor/eslint-plugin-nestjs-typed 可以商用吗？

@darraghor/eslint-plugin-nestjs-typed 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @darraghor/eslint-plugin-nestjs-typed 的下载量有多少？

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

### @darraghor/eslint-plugin-nestjs-typed 还在维护吗？

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

