@elsikora/eslint-plugin-nestjs-typed

中文文档
3.1.0发布于 2026/05/21MITTypeScriptESM + CJS近 30 天下载 1.2万

ESLint plugin for NestJS Typed

原始使用文档
文档目录16 节
  1. 📚 Table of Contents
  2. 📖 Description
  3. 🚀 Features
  4. 🛠 Installation
  5. 💡 Usage
  6. Basic Configuration
  7. Usage with TypeScript
  8. Individual Rule Configuration
  9. Working with Swagger/OpenAPI
  10. Custom Validation Rules
  11. Advanced Guard Usage
  12. 🛣 Roadmap
  13. ❓ FAQ
  14. Frequently Asked Questions
  15. 🔒 License
  16. 📋 Changelog

project-logo

ESLint-Plugin-NestJS-Typed 🎯

Advanced ESLint rules for safer NestJS development with improved type checking

ElsiKora version typescript eslint nestjs license

📚 Table of Contents

📖 Description

ESLint-Plugin-NestJS-Typed is a specialized ESLint plugin designed to enhance the development experience in NestJS applications by providing strict type checking and enforcing best practices. It helps catch common mistakes, ensures consistent API documentation, and maintains code quality across your NestJS projects. The plugin is particularly useful for teams working on large-scale NestJS applications where type safety and consistent patterns are crucial.

🚀 Features

  • ✨ Comprehensive set of NestJS-specific ESLint rules
  • ✨ Strict type checking for Controllers and Injectable services
  • ✨ Automated validation of Swagger/OpenAPI documentation
  • ✨ Detection of missing injectable dependencies
  • ✨ Enforcement of consistent API documentation patterns
  • ✨ Validation of proper decorator usage
  • ✨ Array type checking and validation
  • ✨ Enum handling best practices
  • ✨ Guard implementation verification
  • ✨ Custom validation rules support

🛠 Installation

# 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

💡 Usage

Basic Configuration

Add the plugin to your .eslintrc.js:

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

Usage with TypeScript

Ensure your tsconfig.json has the following options:

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

Individual Rule Configuration

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'
  }
}

Working with Swagger/OpenAPI

Example of proper documentation:

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

Custom Validation Rules

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

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

Advanced Guard Usage

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

🛣 Roadmap

Task / FeatureStatus
Future development plans include:🚧 In Progress
- Support for custom decorators validation🚧 In Progress
- Integration with more NestJS features🚧 In Progress
- Additional rules for microservices architecture🚧 In Progress
- Performance optimization for large codebases🚧 In Progress
- Extended OpenAPI/Swagger validation rules🚧 In Progress
- Custom rule creation helpers🚧 In Progress
Completed tasks from CHANGELOG:
989a57e: chore(ci): streamline release workflow✅ Done
e9c5d16: chore(package): update publishConfig for provenance✅ Done
3c669e8: chore(project-setup): remove obsolete configuration and setup files✅ Done

❓ FAQ

Frequently Asked Questions

Q: Does this plugin work with NestJS v8 and v9? A: Yes, the plugin is compatible with both NestJS v8 and v9.

Q: Can I use this with other ESLint plugins? A: Yes, this plugin works well alongside other ESLint plugins and configurations.

Q: How does it handle custom decorators? A: The plugin provides options to configure custom decorator validation through rule configuration.

Q: Will this plugin affect build performance? A: The plugin is designed to be performant, but complex rules may add minimal overhead to the linting process.

🔒 License

This project is licensed under MIT License - Copyright (c) 2024 ElsiKora.

📋 Changelog

See CHANGELOG.md for details.

版本与发布记录

@elsikora/eslint-plugin-nestjs-typed 共发布 14 个版本,首次发布于 2024/01/04;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.1.0latest2026/05/215 个月前
3.1.0-dev.1beta2026/05/215 个月前
3.0.12025/02/051.8 年前
2.0.42024/10/312 年前
2.0.32024/10/312 年前
2.0.22024/10/312 年前

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

@elsikora/eslint-plugin-nestjs-typed 是什么?

ESLint plugin for NestJS Typed

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