{"record":{"id":"2b75ac3f7640a410","repo":"oxc-project/oxc","slug":"left-hand-side-of-operator-has-no-effect","errorCode":null,"errorMessage":"Left-hand side of `&&` operator has no effect.","messagePattern":"Left-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":16,"sourceCode":"// Based on https://github.com/rust-lang/rust-clippy//blob/6246f0446afbe9abff18e8cc1ebaae7505f7cd9e/clippy_lints/src/operators/const_comparisons.rs\nuse std::cmp::Ordering;\n\nuse oxc_ast::{\n    AstKind,\n    ast::{BinaryExpression, Expression, LogicalExpression, NumericLiteral, UnaryOperator},\n};\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([","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L1-L34","documentation":"From oxlint's `oxc/const-comparisons` (ported from clippy's redundant_comparisons): inside an `&&` chain comparing the same variable against numeric constants in the same direction, this variant fires when the LEFT comparison adds nothing — if the right comparison is true, the left is necessarily true. The labels read 'If this evaluates to true' on the right and 'This will always evaluate to true.' on the left, and the whole chain equals the right comparison alone.","triggerScenarios":"`x <= 500 && x < 400` — `x < 400` implies `x <= 500`, so the left side has no effect; generally `x OP C1 && x OP C2` with same-direction `<`/`<=` (or `>`/`>=`) where the right bound is the stricter one.","commonSituations":"Range guards edited repeatedly until bounds overlap; merging two conditions during a refactor and keeping both; boundary churn between `<` and `<=` forms.","solutions":["Delete the weaker left comparison and keep the stricter right one: `x < 400`","If the left comparison was meant to involve a different variable or constant, fix that identifier or bound","Re-derive the range from the requirement (which values are allowed) instead of stacking comparisons"],"exampleFix":"// before\nif (x <= 500 && x < 400) { /* ... */ }\n\n// after\nif (x < 400) { /* ... */ }","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":["Express ranges in one canonical half-open form: `x >= lo && x < hi`","Add boundary unit tests at both constants so overlapping bounds fail the suite","When editing bounds, re-read the whole condition instead of appending another comparison"],"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"}