no-extra-boolean-cast
Configuration
Rule Details
Disallows unnecessary boolean casts. Using !! (double negation) or Boolean() to convert a value to boolean is redundant when the value is already in a boolean context, such as the test of an if statement.
new Boolean(x) is never flagged because it produces a Boolean object (always truthy) rather than a primitive, so replacing it with a plain value would change semantics.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule accepts a single options object.
enforceForLogicalOperands (legacy)
When true, the rule also reports redundant boolean casts that are operands of || or && when the overall logical expression is used in a boolean context.
enforceForInnerExpressions
A superset of enforceForLogicalOperands. Additionally reports redundant casts on the right-hand side of ??, on the branches of ternaries, and on the last expression of a sequence (a, b, c).