darraghoriordan / eslint-plugin-nestjs-typed

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

all-properties-have-explicit-defined should have option to not trigger on `null` values #50

Closed sosafe-robert-mcauley closed 1 year ago

sosafe-robert-mcauley commented 1 year ago

Fine ESLint plugin, it should be considered required for using class-validator. :)

I'm using this with a non-NestJS project, though, where null values on JSON objects need to be defined explicitly as null rather than being left as undefined.

The all-properties-have-explicit-defined rule is triggering on lines in my class such as this:

  @IsString()
  externalId!: string | null;

I'm currently littering my project with eslint-disable-next-line, but that never sits well with me. I do not want to disable the rule as I do have other properties that can be undefined and the rule is helping me find and assign them IsOptional.

Would it be possible to add an option to the rule, e.g. null-is-required, to work around my situation?

sosafe-robert-mcauley commented 1 year ago

Well, this appears to be my own misunderstanding on how class-validator works! IsOptional is required to allow null values. Sorry about that. :)