{"record":{"id":"23aaf69d0179d5ca","repo":"oxc-project/oxc","slug":"both-sides-of-the-logical-operator-are-equivalent","errorCode":null,"errorMessage":"Both sides of the logical operator are equivalent","messagePattern":"Both sides of the logical operator are equivalent","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/oxc/const_comparisons.rs","lineNumber":65,"sourceCode":"        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(\n    always_truthy: bool,\n    left_span: Span,\n    right_span: Span,\n) -> OxcDiagnostic {\n    let (left_label, right_label) = if always_truthy {\n        (\"If this expression evaluates to false\", \"This expression must evaluate to true\")\n    } else {\n        (\"If this expression evaluates to true\", \"This expression cannot also evaluate to true\")\n    };\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L47-L83","documentation":"The 'equivalent' variant of `oxc/const-comparisons`: the two operands of `&&`/`||` are equality comparisons over the same operand pair, possibly swapped — `a === b && b === a` (matched via `equality_relation` accepting same-order or swapped-order operands with identical operators). The expression always equals either side alone, so one comparison is redundant.","triggerScenarios":"`a === b && b === a`; `a != b && b != a`; equality predicates whose operands were swapped in one copy during a refactor.","commonSituations":"Symmetry checks written 'for safety'; developers unsure whether `===` is symmetric; generated equality predicates and codemod rewrites that swap argument order in one copy.","solutions":["Keep a single comparison: `a === b` (equality operators are symmetric)","Delete the swapped duplicate","If the second comparison was meant to test a different pair, fix the identifiers"],"exampleFix":"// before\nif (a === b && b === a) { /* ... */ }\n\n// after\nif (a === b) { /* ... */ }","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":["Trust that `===` is symmetric: one comparison suffices","Avoid hand-writing symmetry checks; use a deep-equal helper when order matters","Run oxlint so equivalent-operand pairs are flagged"],"tags":["oxlint","oxc","conditions","equality","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-14T00:17:10.932Z"}