Code Monkey home page Code Monkey logo

Comments (6)

darraghoriordan avatar darraghoriordan commented on May 29, 2024 1

I improved the error message for the rule to suggest adding "IsEnum()" for enums

i noticed that i do (try to) check the property type in the rule for enums but maybe it's not working for some reason. The unit tests pass with your scenario, but your scenario also errors for me when in a real nestjs project. So it's likely something to do with the parser? but i'm not 100% sure. IsEnum solves it anyway so i never noticed

from eslint-plugin-nestjs-typed.

darraghoriordan avatar darraghoriordan commented on May 29, 2024 1

Sorry for the dumb question, but can I use IsEnum() for nullable / array properties?

you'll have to test the "null" one works in your scenario. i'm not sure how you're using it.

For the array you must tell the validation decorator it is an enum array:
@IsEnum(Baz, { each: true })

It's described here in the class validator docs: https://github.com/typestack/class-validator#validating-arrays

from eslint-plugin-nestjs-typed.

darraghoriordan avatar darraghoriordan commented on May 29, 2024

The rule uses the enum validation to detect if the non-primitive type is an enum and ignore the rule. So you can prevent the lint error by applying @IsEnum(Baz) or @IsEnum(Bar) in the above cases. If i get a chance i'll try changing it to check the type of Bar/Baz is an actual enum. But it might take me a while 😂

(it's a good idea to validate that the client supplied values are valid enum values anyway)

from eslint-plugin-nestjs-typed.

iddan avatar iddan commented on May 29, 2024

Sorry for the dumb question, but can I use IsEnum() for nullable / array properties?

from eslint-plugin-nestjs-typed.

iddan avatar iddan commented on May 29, 2024

Can we add an auto-fix for using the IsEnum() decorator?

from eslint-plugin-nestjs-typed.

darraghoriordan avatar darraghoriordan commented on May 29, 2024

i believe this is resolved

from eslint-plugin-nestjs-typed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.