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

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

版本：2\.2\.0
npm 元数据更新时间：2024-03-31T15:36:36.045Z
中文译文更新时间：2026-11-17T03:00:45.351Z
软件包许可：ISC

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

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

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

- 包体积（解压后）：256 kB，49 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：^18\.18\.0 \|\| \>=20\.0\.0
- 运行依赖：1 个
- peer 依赖：@typescript-eslint/parser \>=7\.0\.0，@typescript-eslint/scope-manager \>=7\.0\.0，@typescript-eslint/utils \>=7\.0\.0，class-validator \*，reflect-metadata \*，eslint ^8\.56\.0
- 首次发布：2022-01-27T06:26:48.459Z
- 最新版本发布：2024-03-31T15:36:35.860Z
- 近 30 天下载量：8533（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：21（近 12 个月 0 个）

## 中文简介

Eslint 巢项目的规则

## 安装

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

也可以使用：`pnpm add @greguintow/eslint-plugin-nestjs-typed`、`yarn add @greguintow/eslint-plugin-nestjs-typed`、`bun add @greguintow/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)

## 关于版本的说明

-   版本 `5.x` 支持 Eslint 版本 `>=8.x` 和打字机 eslint 解析器 `^7`
-   版本 `4.x` 支持 Eslint 版本 `>=8.x` 和打字机 eslint 解析器 `^6`
-   版本 `3.x` 支持 Eslint 版本 `>=8.x` 和打字机 eslint 解析器 `^5`
-   版本 `2.x` 支持 Eslint 版本 `<=7.x` 和打字机 eslint 解析器 `^4`

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://github.com/darraghoriordan/eslint-plugin-nestjs-typed/issues/new?title=New%20Rule%20Suggestion&labels=Rule%20Suggestion&body=Hi!%20I%20have%20an%20idea%20for%20a%20rule...) 提交新一期!

## 现有规则索引

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

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

"被推荐"这个名称是"埃斯林特会". 此插件中的一些规则是有观点的, 必须在您的 eslintrc 文件中明确打开 .

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

如果使用 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
module.exports = {
    env: {
        es6: true,
    },
    extends: ["plugin:@darraghor/nestjs-typed/recommended"],
    parser: "@typescript-eslint/parser",
    parserOptions: {
        project: ["./tsconfig.json"],
        sourceType: "module",
        ecmaVersion: "es2019",
    },
    plugins: ["@darraghor/nestjs-typed"],
};
```

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

已经应用了一些默认值 .

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

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

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

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

## 常见问题

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

Eslint 巢项目的规则

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

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

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

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

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

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

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

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

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

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

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

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

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

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

