darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
159 stars 30 forks source link

Suggestion: `@IsOptional()` or `@ValidateIf()` by themselves should not satisfy `all-properties-are-whitelisted` #189

Open abrindam opened 1 month ago

abrindam commented 1 month ago

Since these two decorators exist to conditionally ignore other validation decorators, it is probably a mistake if no other validation decorators are present.

The following is probably a mistake, otherProperty needs another validation decorator.

export class CreateOrganisationDto {
    @ApiProperty({type: Person, isArray: true})
    @ValidateNested({each: true})
    members!: MyClass[];

    @ApiProperty()
    @IsOptional()
    otherProperty?: MyClass;
}

Alternatively, this could be a totally separate rule (no-useless-validation-decorators ?) but that seems excessively complex to me.

I'd be happy to open a PR for this if the idea has merit!

darraghoriordan commented 1 month ago

I think that maybe this should already be part of this rule: https://github.com/darraghoriordan/eslint-plugin-nestjs-typed/blob/main/src/docs/rules/all-properties-are-whitelisted.md

Maybe the list of decorators that triggers that rule to check all the other properties have a validation decorator, is missing "IsOptional()" ?

But yes feel free to create a PR 👍