darraghoriordan / eslint-plugin-nestjs-typed

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

fix: detect null primitive types #40

Closed austinwoon closed 1 year ago

austinwoon commented 1 year ago

Closes #39

Thanks again for creating this set of plugins. We're currently using the validateNonPrimitiveNeedsDecorators rule and realise that the linter was throwing false positives for matches in #39

This happens because we are not tracking null as a primitive type.

Although it might not make sense to send a null in the request dto, we were combining both ORM decorators (typeorm) and request validators in our project. As such, a class property could be null for nullable database columns.

Tested and verified that existing logic does not break, and new use case is supported!

darraghoriordan commented 1 year ago

Hey,

Thanks for this. sounds reasonable! Will merge when the conflict is resolved

dar

================

as an aside...

I try to use DTOs instead of returning the typeorm entities directly but it does mean lots of boilerplate in my code at times.

To change the nulls I used to use the @AfterXXX decorators from typeorm to change entity properties to values I wanted in DTOs e.g. nulls to undefined or nulls to empty arrays.

I describe it here: https://www.darraghoriordan.com/2021/10/19/populating-empty-arrays-type-orm/

austinwoon commented 1 year ago

I try to use DTOs instead of returning the typeorm entities directly but it does mean lots of boilerplate in my code at times.

This is definitely the best way to go about it, we've encountered alot of issues mixing our request, response and entities typing + decorators in our repo haha.

Thanks for sharing the snippet! It's definitely a pattern we could use!

Thanks for this. sounds reasonable! Will merge when the conflict is resolved

Rebased the branch and resolved conflicts!

darraghoriordan commented 1 year ago

:tada: This PR is included in version 3.17.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: