@greguintow/eslint-plugin-nestjs-typed

中文文档
2.2.0发布于 2024/03/31ISCTypeScriptCommonJS近 30 天下载 8533

Eslint 巢项目的规则

中文使用文档
文档目录10 节
  1. 关于版本的说明
  2. 有规则吗?
  3. 现有规则索引
  4. 这个包裹是给谁用的?
  5. 1. 检测巢穴依赖性注射问题
  6. 2. 使用 Open Api / Swagger 装饰并自动生成客户端
  7. 3. 帮助预防错误
  8. 4. 警卫
  9. 要安装
  10. 要配置

commit npm npm-tag size types

关于版本的说明

  • 版本 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 对版本.

有规则吗?

恶心! 点击这里 提交新一期!

现有规则索引

类别规则是在推荐规则?
巢穴模块和依赖性注射provided-injected-should-match-factory-parametersY
injectable-should-be-providedY
巢斯瓦格岛api-property-matches-property-optionalityY
controllers-should-supply-api-tagsY
api-method-should-specify-api-response无
api-method-should-specify-api-operationY
api-enum-property-best-practicesY
api-property-returning-array-should-set-arrayY
防止错误param-decorator-name-matches-route-paramY
validate-nested-of-array-should-set-eachY
validated-non-primitive-property-needs-type-decoratorY
all-properties-are-whitelistedY
all-properties-have-explicit-definedY
no-duplicate-decoratorsY
警卫validation-pipe-should-forbid-unknownY
api-methods-should-be-guarded无
代码一致性sort-module-metadata-arrays无

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

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

这个包裹是给谁用的?

如果使用 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 并添加推荐的规则集

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 规则设置在推荐的规则集之后.

// 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 共发布 21 个版本,首次发布于 2022/01/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.0latest2024/03/312 年前
2.1.12024/03/302 年前
2.1.02024/03/302 年前
2.0.02024/03/172 年前
1.3.42023/11/143 年前
1.3.32023/11/143 年前

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

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