3.0.1 • Published 9 months ago

@elsikora/eslint-plugin-nestjs-typed v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

📚 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.

3.0.1

9 months ago

2.0.3

12 months ago

2.0.2

12 months ago

2.0.4

12 months ago

2.0.1

12 months ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago