{"record":{"id":"557744a4104f382a","repo":"oxc-project/oxc","slug":"right-hand-side-of-operator-has-no-effect","errorCode":null,"errorMessage":"Right-hand side of `&&` operator has no effect.","messagePattern":"Right-hand side of `&&` operator has no effect\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/const_comparisons.rs","lineNumber":25,"sourceCode":"};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::{BinaryOperator, LogicalOperator};\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_same_expression};\n\nfn redundant_left_hand_side(left_span: Span, right_span: Span, help: String) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Left-hand side of `&&` operator has no effect.\")\n        .with_help(help)\n        .with_labels([\n            right_span.label(\"If this evaluates to `true`\"),\n            left_span.label(\"This will always evaluate to true.\"),\n        ])\n}\n\nfn redundant_right_hand_side(right_span: Span, left_span: Span, help: String) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Right-hand side of `&&` operator has no effect.\")\n        .with_help(help)\n        .with_labels([\n            left_span.label(\"If this evaluates to `true`\"),\n            right_span.label(\"This will always evaluate to true.\"),\n        ])\n}\n\nfn impossible(span: Span, span1: Span, x2: &str, x3: &str, x4: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected constant comparison\").with_help(x4.to_string()).with_labels([\n        span.label(format!(\"Requires that {x2}\")),\n        span1.label(format!(\"Requires that {x3}\")),\n    ])\n}\n\nfn constant_comparison_diagnostic(\n    span: Span,\n    evaluates_to: bool,\n    help: String,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L7-L43","documentation":"The mirror variant of `oxc/const-comparisons`: in an `&&` chain of same-direction constant comparisons on one variable, the RIGHT comparison is implied by the left — if the left is true, the right is always true — so the right operand of `&&` has no effect. The rule's doc example is `status_code < 200 && status_code <= 299`, which is simply `status_code < 200`.","triggerScenarios":"`status_code < 200 && status_code <= 299`; `n > 10 && n > 5`; any same-direction pair on one variable where the left bound is the stricter one.","commonSituations":"HTTP status range checks (2xx/4xx) written with overlapping bounds; threshold checks tightened on one side only; leftover comparisons after requirements changed.","solutions":["Remove the weaker right comparison and keep the stricter left one: `status_code < 200`","If a wider range was intended (e.g. all of 2xx), write `status_code >= 200 && status_code < 300`","Add boundary unit tests at the exact constants to lock in the intended range"],"exampleFix":"// before\nconst ok = status_code < 200 && status_code <= 299;\n\n// after\nconst ok = status_code < 200;\n// or, if the full 2xx range was intended:\n// const ok = status_code >= 200 && status_code < 300;","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":["Write range checks as `x >= lo && x < hi` and delete any leftover weaker bound","Boundary-test both endpoints of every range constant","Let oxlint flag overlapping same-direction comparisons before merge"],"tags":["oxlint","oxc","conditions","logic-bug","javascript","static-analysis"],"backgroundTag":"redundant-range-comparison","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"}