[Bug]: no-leaked-render
won't accept explicit Boolean()
coercion, only implicit coercion with !!
#3811
Open
2 tasks done
Labels
Is there an existing issue for this?
Description Overview
The goal of the rule - as I understand it - is to ensure that values used in a JSX expression are verifiably booleans, so that they don't throw. Makes sense. But, the only acknowledged method - in rule docs and seemingly in the code - of coercing a value to boolean is the use of
!!
. This use is extremely common, and many folks (including me) don't even think to use the more explicit method of casting a value to boolean with theBoolean()
constructor.But, if you're being super oriented toward readability, that "implicit" coercion takes an extra couple seconds to read and parse, and junior devs may not even understand it. So, there's even an integrated eslint rule
no-implicit-coercion
which forbids!!value
and recommendsBoolean(value)
instead. And... we use that rule. (As part of Tim W. James' wonderful eslint-config).So, I tried converting my statement to use
!!
to satisfy this rule... only to run into a conflict with that other one. So, I took the advice to "useBoolean(value)
instead"... only to realize that this rule doesn't understand it as an acceptable way to ensure the value is boolean by the time it's evaluated.Code:
This rule throws a warning from:
{showDevtools && <ReactQueryDevtools position="right" />}
This rule is OK with:
{!!showDevtools && <ReactQueryDevtools position="right" />}
, but that triggers a warning from eslint's own no-implicit-coercionSo I tried:
{Boolean(showDevtools) && <ReactQueryDevtools position="right" />}
, but this rule doesn't understand that as a legitimate way to get it done. (And, it's also entirely absent from the docs, which suggests to me it's intentional.)Expected Behavior
The rule should permit use of
Boolean(value)
, not just use of!!value
eslint-plugin-react version
v7.35.0
eslint version
v8.57.0
node version
v22.7.0
The text was updated successfully, but these errors were encountered: