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

[Bug]: jsx-no-leaked-render report && in prop #3719

Open
2 tasks done
AhmedBaset opened this issue Mar 18, 2024 · 5 comments · May be fixed by #3746
Open
2 tasks done

[Bug]: jsx-no-leaked-render report && in prop #3719

AhmedBaset opened this issue Mar 18, 2024 · 5 comments · May be fixed by #3746

Comments

@AhmedBaset
Copy link

AhmedBaset commented Mar 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Imagine you have a prop (e.g. isOpen), you want to set the value as firstCondition === true && anotherCondition === true. Currently the plugin report wrongly this kind of code which should be valid.

image

Expected Behavior

I expect to not throw

eslint-plugin-react version

7.34.1

eslint version

8.57.0

node version

18

@AhmedBaset AhmedBaset added the bug label Mar 18, 2024
@ljharb
Copy link
Member

ljharb commented Mar 18, 2024

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

@AhmedBaset
Copy link
Author

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.

@ljharb
Copy link
Member

ljharb commented Mar 21, 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.

@AhmedBaset
Copy link
Author

I understand well && and its cons/pros.

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

@ljharb
Copy link
Member

ljharb commented Mar 21, 2024

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

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

Successfully merging a pull request may close this issue.

2 participants