oxc-project/oxc · error
Redundant Boolean call
Error message
Redundant Boolean call
What it means
Diagnostic from oxlint's port of the ESLint no-extra-boolean-cast rule. It fires when a Boolean(...) call sits in a position JavaScript already coerces to a boolean: an if/while/do-while/for condition, a ternary test, the operand of !, or another Boolean() argument. The surrounding context guarantees a boolean, so the cast is dead code. With enforceForInnerExpressions: true (default false) it also flags casts inside sub-expressions whose result feeds a boolean context.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_extra_boolean_cast.rs:33
operator::{LogicalOperator, UnaryOperator},
precedence::{GetPrecedence, Precedence},
};
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::{get_precedence, pad_fix_with_token_boundary},
};
fn no_extra_double_negation_cast_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Redundant double negation")
.with_help("Remove the double negation as it will already be coerced to a boolean")
.with_label(span)
}
fn no_extra_boolean_cast_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Redundant Boolean call")
.with_help("Remove the Boolean call as it will already be coerced to a boolean")
.with_label(span)
}
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoExtraBooleanCast {
/// when set to `true`, in addition to checking default contexts, checks
/// whether extra boolean casts are present in expressions whose result is
/// used in a boolean context. See examples below. Default is `false`,
/// meaning that this rule by default does not warn about extra booleans
/// cast inside inner expressions.
#[serde(alias = "enforceForLogicalOperands")]
pub enforce_for_inner_expressions: bool,
}
declare_oxc_lint!(
/// ### What it doesView on GitHub (pinned to e1e7af627c)
Solutions
- Remove the cast and use the value directly (if (x) instead of if (Boolean(x))).
- If the pattern is !!Boolean(v), drop both the call and the negations.
- If the cast is intentional for readability, suppress the line with // oxlint-disable-next-line eslint/no-extra-boolean-cast.
- Keep enforceForInnerExpressions: false in the rule config to avoid reports on inner expressions.
Example fix
// before
if (Boolean(user.isActive)) {
render();
}
// after
if (user.isActive) {
render();
} Defensive patterns
Strategy: validation
Validate before calling
const redundant = /\b(?:if|while)\s*\(\s*(?:!!\s*)?Boolean\s*\(/.test(source);
if (redundant) failFast('no-extra-boolean-cast will fire'); Prevention
- Write conditions as bare truthiness tests; never wrap test expressions in Boolean() or !!.
- Keep oxlint in a pre-commit hook so redundant casts never reach review.
- Run npx oxlint -A all -D no-extra-boolean-cast src/ when refactoring conditions.
When it happens
Trigger: if (Boolean(x)) {...}; while (!!Boolean(done)) {...}; const r = Boolean(a) ? 1 : 0 (cast in the ternary test); !Boolean(visible); Boolean(Boolean(v)) (nested calls); with enforceForInnerExpressions: true: if (a && Boolean(b)) {...}.
Common situations: Defensive 'make it boolean' casts copied from older code or earlier autofixes; reviewers adding Boolean() in conditions for readability; enabling enforceForInnerExpressions during an oxlint upgrade, which suddenly flags inner expressions that default mode ignored.
Related errors
- This label '{label_name}' is unnecessary
- Unexpected implicit coercion to boolean
- Empty array binding pattern
- Empty object binding pattern
- Unexpected constant {lhs_name} on the left-hand side of a {e
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/56cfdf398bcae727.
Report an issue: GitHub.