@darraghor/eslint-plugin-nestjs-typed

中文文档
7.5.8发布于 2026/10/05ISCTypeScriptES Module构建来源已验证近 30 天下载 112.8万

Eslint 巢项目的规则

中文使用文档
文档目录15 节
  1. 支持此插件
  2. 关于版本的说明
  3. Eslint 9.x 支持
  4. TS Eslint 版本支持
  5. 有规则吗?
  6. 现有规则索引
  7. 这个包裹是给谁用的?
  8. 1. 检测巢穴依赖性注射问题
  9. 2. 使用 Open Api / Swagger 装饰并自动生成客户端
  10. 3. 帮助预防错误
  11. 4. 警卫
  12. 要安装
  13. 要配置
  14. 注射器可以扫描所有东西
  15. 解除规则

commit npm npm-tag size types

雀巢JS Eslint 插件

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

跳转到 如何配置 但是如果你有问题 回来阅读整个文件.

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 (中文(简体) )

但请提交公关 帮助所有的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 版本 .

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

见 如何配置 需要更多信息.

TS Eslint 版本支持

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

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

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

有规则吗?

请提交拉力请求 见 捐款。 。 。 .

现有规则索引

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

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

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

这个包裹是给谁用的?

如果使用 NestJs (则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://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

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 配置, 导入插件并添加平面推荐规则集 .

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

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"导出中的旧风格配置.

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

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

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

注射器可以扫描所有东西

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

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

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

// 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",
   }

版本与发布记录

@darraghor/eslint-plugin-nestjs-typed 共发布 315 个版本,首次发布于 2021/06/04;过去 12 个月发布了 88 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.5.8latest2026/10/051 个月前
7.5.72026/10/051 个月前
7.5.62026/09/221 个月前
7.5.52026/09/191 个月前
7.5.42026/09/181 个月前
7.5.32026/09/131 个月前

其他发布通道:next → 6.1.0-rc.5。

关于 @darraghor/eslint-plugin-nestjs-typed 的常见问题

@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 和提交记录判断。