Giter Site home page Giter Site logo

Comments (13)

AhmedBaset avatar AhmedBaset commented on May 25, 2024 1

Yes.

Done in #3754

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

i agree, this should be valid (altho !!firstCondition && !!anotherCondition would be more idiomatic)

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

One more thing is frustrating to me.

number && value might cause unintentional reslut but boolean && value won't.

Why the plugin requires ternary all the time even when no potential unexpected result? Could we use the TypeScrypt parser to only report the potential errors? && conditional rendering is a JS feature not something developer should avoid.

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

@A7med3bdulBaset specifically because a 0 is falsy but will render a literal zero - that's the point of the rule, and indeed is why && conditional rendering is dangerous.

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

I understand well && and its cons/pros.

I know 0 && content will render 0. My point is why boolean && content, contentOrNullOrUndefinedOrBoolean && content is prevented?

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

I agree that neither of those should be prevented when the type is known.

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

Thanks @akulsr0 for working on this

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

I know 0 && content will render 0. My point is why boolean && content, contentOrNullOrUndefinedOrBoolean && content is prevented?

I agree that neither of those should be prevented when the type is known.

@ljharb, should I create an issue for this?

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

@AhmedBaset if, with the latest unreleased code, you still have an issue, please do file one.

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

<Comp prop={cond1 && cond2} /> was solved. But, dataOrUndefined && data... still an issue. IMO the rule should only complain if the left side is of type number.

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

More specifically, it should only complain if the left side is a known type and is not a number.

This should also be an option, I'd think, because TS isn't actually "type safety" and folks may not want to rely on it.

from eslint-plugin-react.

AhmedBaset avatar AhmedBaset commented on May 25, 2024

More specifically, it should only complain if the left side is a known type and is not a number.

This should also be an option, I'd think, because TS isn't actually "type safety" and folks may not want to rely on it.

hmm. then, worth be an issue?

from eslint-plugin-react.

ljharb avatar ljharb commented on May 25, 2024

Yes.

from eslint-plugin-react.

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.