{"record":{"id":"56cfdf398bcae727","repo":"oxc-project/oxc","slug":"redundant-boolean-call","errorCode":null,"errorMessage":"Redundant Boolean call","messagePattern":"Redundant Boolean call","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_extra_boolean_cast.rs","lineNumber":33,"sourceCode":"    operator::{LogicalOperator, UnaryOperator},\n    precedence::{GetPrecedence, Precedence},\n};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{get_precedence, pad_fix_with_token_boundary},\n};\n\nfn no_extra_double_negation_cast_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Redundant double negation\")\n        .with_help(\"Remove the double negation as it will already be coerced to a boolean\")\n        .with_label(span)\n}\n\nfn no_extra_boolean_cast_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Redundant Boolean call\")\n        .with_help(\"Remove the Boolean call as it will already be coerced to a boolean\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoExtraBooleanCast {\n    /// when set to `true`, in addition to checking default contexts, checks\n    /// whether extra boolean casts are present in expressions whose result is\n    /// used in a boolean context. See examples below. Default is `false`,\n    /// meaning that this rule by default does not warn about extra booleans\n    /// cast inside inner expressions.\n    #[serde(alias = \"enforceForLogicalOperands\")]\n    pub enforce_for_inner_expressions: bool,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_extra_boolean_cast.rs#L15-L51","documentation":"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.","triggerScenarios":"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)) {...}.","commonSituations":"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.","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."],"exampleFix":"// before\nif (Boolean(user.isActive)) {\n  render();\n}\n\n// after\nif (user.isActive) {\n  render();\n}","handlingStrategy":"validation","validationCode":"const redundant = /\\b(?:if|while)\\s*\\(\\s*(?:!!\\s*)?Boolean\\s*\\(/.test(source);\nif (redundant) failFast('no-extra-boolean-cast will fire');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["eslint","oxlint","lint","boolean","dead-code"],"backgroundTag":"redundant-boolean-cast","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}