Disallow unnecessary boolean casts
The "extends": "eslint:recommended"
property in a configuration file enables this rule
Some problems reported by this rule are automatically fixable by the --fix
command line option
In contexts such as an if
statement’s test where the result of the expression will already be coerced to a Boolean, casting to a Boolean via double negation (!!
) or a Boolean
call is unnecessary. For example, these if
statements are equivalent:
This rule disallows unnecessary boolean casts.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule has an object option:
"enforceForLogicalOperands"
when set to true
, in addition to checking default contexts, checks whether the extra boolean cast is contained within a logical expression. Default is false
, meaning that this rule by default does not warn about extra booleans cast inside logical expression.Examples of incorrect code for this rule with "enforceForLogicalOperands"
option set to true
:
Examples of correct code for this rule with "enforceForLogicalOperands"
option set to true
:
This rule was introduced in ESLint v0.4.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-extra-boolean-cast