SLint-Plugin-NestJS-Typed QQ (英语)
改进型号检查后用于安全巢穴JS开发的高级ESLint规则
目录
说明
ESLint-Plugin-NestJS-Typed是一个专门的ESLint插件,旨在通过提供严格的类型检查和执行最佳做法来增强NestJS应用的开发经验. 它有助于捕捉常见错误,确保 API 文档的一致性, 并维护代码质量 整个您的 NestJS 项目。 该插件对从事大型NestJS应用的团队特别有用,因为类型安全和一致的规律至关重要.
* 特性
- ✨ 一整套针对巢穴的ESLint规则
- ✨ 严格控制器和可注入服务的类型检查
- ✨ Swagger/ OpenAPI 文件的自动验证
- ✨ 发现缺失的可注射依赖
- ✨ 执行一致的API文件模式
- ✨ 鉴定适当的装饰使用
- ✨ 阵列类型检查和验证
- ✨ Enum 处理最佳做法
- ✨ 警卫执行核查
- ✨ 自定义验证规则支持
* 安装
# 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数字 :
module.exports = {
plugins: ['@elsikora/nestjs-typed'],
extends: [
'plugin:@elsikora/nestjs-typed/recommended'
]
}
使用类型脚本
保证您 tsconfig.json 有以下选项:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
单个规则配置
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 合作
适当文件的例子:
@ApiTags('Users')
@Controller('users')
export class UsersController {
@Get()
@ApiOperation({ summary: 'Get all users' })
@ApiOkResponse({ type: [UserDto] })
async getUsers(): Promise<UserDto[]> {
return this.usersService.findAll();
}
}
自定义验证规则
class CreateUserDto {
@ApiProperty()
@IsString()
@IsDefined()
name: string;
@ApiPropertyOptional()
@IsOptional()
@IsEmail()
email?: string;
}
高级后卫使用
@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 更改日志
见 变动情况 详细情况.