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

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

版本：3\.1\.0
npm 元数据更新时间：2026-05-21T00:25:03.785Z
中文译文更新时间：2026-11-13T14:11:58.469Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：396 kB，259 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：5 个
- peer 依赖：@typescript-eslint/parser \>=8\.0\.0，class-validator \>=0\.14\.1，eslint \>=9\.18\.0
- 首次发布：2024-01-03T17:40:04.372Z
- 最新版本发布：2026-05-21T00:25:03.649Z
- 近 30 天下载量：11716（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：14（近 12 个月 2 个）

## 中文简介

NestJS 输入的 ESLint 插件

## 安装

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

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

## README

![project-logo](https://6jft62zmy9nx2oea.public.blob.vercel-storage.com/Untitled-1-aJXyIFQkIShtr42QWRvkpSx6b2YOJl.png)

# SLint-Plugin-NestJS-Typed QQ (英语)

_改进型号检查后用于安全巢穴JS开发的高级ESLint规则_

 [![ElsiKora](https://img.shields.io/badge/MADE%20BY%20ElsiKora-333333.svg?style=for-the-badge)](https://elsikora.com/)![version](https://img.shields.io/badge/version-blue.svg?style=for-the-badge&logo=npm&logoColor=white) ![typescript](https://img.shields.io/badge/typescript-blue.svg?style=for-the-badge&logo=typescript&logoColor=white) ![eslint](https://img.shields.io/badge/eslint-purple.svg?style=for-the-badge&logo=eslint&logoColor=white) ![nestjs](https://img.shields.io/badge/nestjs-red.svg?style=for-the-badge&logo=nestjs&logoColor=white) ![license](https://img.shields.io/badge/license-green.svg?style=for-the-badge&logo=license&logoColor=white)

## 目录

-   [说明](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--description)
-   [特征](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--features)
-   [安装](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--installation)
-   [使用量](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--usage)
-   [路线图](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--roadmap)
-   [财务问题](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--faq)
-   [许可证](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/#readme--license)

## 说明

ESLint-Plugin-NestJS-Typed是一个专门的ESLint插件,旨在通过提供严格的类型检查和执行最佳做法来增强NestJS应用的开发经验. 它有助于捕捉常见错误,确保 API 文档的一致性, 并维护代码质量 整个您的 NestJS 项目。 该插件对从事大型NestJS应用的团队特别有用,因为类型安全和一致的规律至关重要.

## \* 特性

-   ✨ **一整套针对巢穴的ESLint规则**
-   ✨ **严格控制器和可注入服务的类型检查**
-   ✨ **Swagger/ OpenAPI 文件的自动验证**
-   ✨ **发现缺失的可注射依赖**
-   ✨ **执行一致的API文件模式**
-   ✨ **鉴定适当的装饰使用**
-   ✨ **阵列类型检查和验证**
-   ✨ **Enum 处理最佳做法**
-   ✨ **警卫执行核查**
-   ✨ **自定义验证规则支持**

## \* 安装

```bash
# Using npm
npm install --save-dev eslint-plugin-nestjs-typed

# Using yarn
yarn add -D eslint-plugin-nestjs-typed

# Using pnpm
pnpm add -D eslint-plugin-nestjs-typed
```

## 使用量

## 基本配置

将插件添加到您的 `.eslintrc.js`数字 :

```javascript
module.exports = {
  plugins: ['@elsikora/nestjs-typed'],
  extends: [
    'plugin:@elsikora/nestjs-typed/recommended'
  ]
}
```

## 使用类型脚本

保证您 `tsconfig.json` 有以下选项:

```json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}
```

## 单个规则配置

```javascript
module.exports = {
  rules: {
    '@elsikora/nestjs-typed/injectable-should-be-provided': ['error', {
      src: ['src/**/*.ts'],
      filterFromPaths: ['node_modules', '.test.', '.spec.']
    }],
    '@elsikora/nestjs-typed/api-method-should-specify-api-response': 'error',
    '@elsikora/nestjs-typed/controllers-should-supply-api-tags': 'error'
  }
}
```

## 与 Swagger/ OpenAPI 合作

适当文件的例子:

```typescript
@ApiTags('Users')
@Controller('users')
export class UsersController {
  @Get()
  @ApiOperation({ summary: 'Get all users' })
  @ApiOkResponse({ type: [UserDto] })
  async getUsers(): Promise<UserDto[]> {
    return this.usersService.findAll();
  }
}
```

## 自定义验证规则

```typescript
class CreateUserDto {
  @ApiProperty()
  @IsString()
  @IsDefined()
  name: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsEmail()
  email?: string;
}
```

## 高级后卫使用

```typescript
@Controller('protected')
@UseGuards(AuthGuard())
export class ProtectedController {
  @Get()
  @ApiOperation({ summary: 'Protected endpoint' })
  @ApiOkResponse({ type: String })
  getProtectedData(): string {
    return 'Protected data';
  }
}
```

## \* 路线图

| 任务/ 特性 | 状态 |
| --- | --- |
| 未来的发展计划包括: | 执行中 |
| \- 支持自定义装饰器验证 | 执行中 |
| \- 与更多的雀巢JS特征相结合 | 执行中 |
| \- 微型服务架构的附加规则 | 执行中 |
| \- 大型密码库的性能优化 | 执行中 |
| \- 扩展的 OpenAPI/ Swagger 验证规则 | 执行中 |
| \- 自定义规则创建助手 | 执行中 |
| **变换组已完成的任务:** |  |
| 989a57e:core(ci):精简发布工作流程 | 完毕 |
| e9c5d16: crore( 包): 更新发布 Config 出处 | 完毕 |
| 3c669e8: core( 项目设置):去掉过时的配置和设置文件 | 完毕 |

## 问 题

## 经常被问到的问题

**问题:这个插件与 NestJS v8 和 v9 有用吗?** 答:是的,插件与NestJS v8和v9都兼容.

**问:我可以用其他ESLint插件吗?** A:是的,这个插件与其他ESLint插件和配置一起效果良好.

**问:它如何处理自定义的装饰?** A:插件提供了通过规则配置配置配置自定义装饰器验证的选项.

**问题: 此插件会影响构建性能吗 ?** A:插件被设计成是表演者,但复杂的规则可能会给起伏过程增加最小的间接费用.

## 许可证

这个项目的许可证根据 **麻省理工学院许可证-版权(c) 2024 Elsi Kora**。 。 。 .

## QQ 更改日志

见 [变动情况](https://npmcn.com/package/%40elsikora/eslint-plugin-nestjs-typed/CHANGELOG.md) 详细情况.

## 常见问题

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

NestJS 输入的 ESLint 插件

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

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

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

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

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

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

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

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

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

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

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

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

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

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

