{"record":{"id":"ef6900d541477302","repo":"oxc-project/oxc","slug":"both-sides-of-the-logical-operator-are-the-same","errorCode":null,"errorMessage":"Both sides of the logical operator are the same","messagePattern":"Both sides of the logical operator are the same","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/oxc/const_comparisons.rs","lineNumber":55,"sourceCode":"    ])\n}\n\nfn constant_comparison_diagnostic(\n    span: Span,\n    evaluates_to: bool,\n    help: String,\n    precedence_note: Option<String>,\n) -> OxcDiagnostic {\n    let diagnostic =\n        OxcDiagnostic::warn(format!(\"This comparison will always evaluate to {evaluates_to}\"))\n            .with_help(help)\n            .with_label(span);\n\n    if let Some(note) = precedence_note { diagnostic.with_note(note) } else { diagnostic }\n}\n\nfn identical_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Both sides of the logical operator are the same\")\n                    .with_help(\"This logical expression will always evaluate to the same value as the expression itself.\")\n                    .with_labels([\n                        left_span.label(\"If this expression evaluates to true\"),\n                        right_span\n                            .label(\"This expression will always evaluate to true\"),\n                    ])\n}\n\nfn equivalent_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Both sides of the logical operator are equivalent\")\n        .with_help(\"This logical expression will always evaluate to the same value as either side.\")\n        .with_labels([\n            left_span.label(\"If this expression evaluates to true\"),\n            right_span.label(\"This equivalent expression will always evaluate to true\"),\n        ])\n}\n\nfn complementary_expressions_logical_operator(","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L37-L73","documentation":"Reported by `oxc/const-comparisons` when both operands of an `&&`/`||` expression are structurally the same expression (`is_same_expression`), e.g. `x && x`. The logical expression always evaluates to the same value as the operand itself, so the second evaluation is pure redundancy (and a duplicate side effect if the operand were a call). This check runs before the equivalent and complementary variants.","triggerScenarios":"`cond && cond`, `isValid || isValid`; duplicated conditions inside a long boolean chain.","commonSituations":"Merging two conditions and forgetting to delete one; merge-conflict resolution leaving both copies; long `if` chains where a duplicated term goes unnoticed.","solutions":["Keep one operand: `cond`","If a second, different condition was intended, restore it","Run oxlint so duplicated logical operands are flagged automatically"],"exampleFix":"// before\nif (isValid && isValid) { /* ... */ }\n\n// after\nif (isValid) { /* ... */ }","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — correctness rule (on in the default category set)\n{\n  \"rules\": { \"oxc/const-comparisons\": \"error\" }\n}\n// CLI: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After merging conditions or resolving merge conflicts, scan the chain for duplicate terms","Keep boolean chains short; extract named predicates for readability","Run oxlint in CI to catch duplicated logical operands"],"tags":["oxlint","oxc","conditions","logic","javascript","static-analysis"],"backgroundTag":"duplicate-logical-operand","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}