Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abrindam opened this issue Jun 25, 2024 · 1 comment

Comments

@abrindam
Copy link
Contributor

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
Copy link
Owner

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants