oxc-project/oxc · error · OxcDiagnostic

Left-hand side of `&&` operator has no effect.

Error message

Left-hand side of `&&` operator has no effect.

What it means

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.

Source

Thrown at crates/oxc_linter/src/rules/oxc/const_comparisons.rs:16

// Based on https://github.com/rust-lang/rust-clippy//blob/6246f0446afbe9abff18e8cc1ebaae7505f7cd9e/clippy_lints/src/operators/const_comparisons.rs
use std::cmp::Ordering;

use oxc_ast::{
    AstKind,
    ast::{BinaryExpression, Expression, LogicalExpression, NumericLiteral, UnaryOperator},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::{BinaryOperator, LogicalOperator};

use crate::{AstNode, context::LintContext, rule::Rule, utils::is_same_expression};

fn redundant_left_hand_side(left_span: Span, right_span: Span, help: String) -> OxcDiagnostic {
    OxcDiagnostic::warn("Left-hand side of `&&` operator has no effect.")
        .with_help(help)
        .with_labels([
            right_span.label("If this evaluates to `true`"),
            left_span.label("This will always evaluate to true."),
        ])
}

fn redundant_right_hand_side(right_span: Span, left_span: Span, help: String) -> OxcDiagnostic {
    OxcDiagnostic::warn("Right-hand side of `&&` operator has no effect.")
        .with_help(help)
        .with_labels([
            left_span.label("If this evaluates to `true`"),
            right_span.label("This will always evaluate to true."),
        ])
}

fn impossible(span: Span, span1: Span, x2: &str, x3: &str, x4: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected constant comparison").with_help(x4.to_string()).with_labels([

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Delete the weaker left comparison and keep the stricter right one: `x < 400`
  2. If the left comparison was meant to involve a different variable or constant, fix that identifier or bound
  3. Re-derive the range from the requirement (which values are allowed) instead of stacking comparisons

Example fix

// before
if (x <= 500 && x < 400) { /* ... */ }

// after
if (x < 400) { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — correctness rule (on in the default category set)
{
  "rules": { "oxc/const-comparisons": "error" }
}
// CLI: npx oxlint src/

Prevention

When it happens

Trigger: `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.

Common situations: Range guards edited repeatedly until bounds overlap; merging two conditions during a refactor and keeping both; boundary churn between `<` and `<=` forms.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/2b75ac3f7640a410. Report an issue: GitHub.