oxc-project/oxc · warning · OxcDiagnostic

Unexpected double comparisons.

Error message

Unexpected double comparisons.

What it means

Oxlint rule `oxc/double-comparisons` (ported from clippy) detects two comparisons of the same operands joined by `||` or `&&` that collapse into one operator: `(==|===) || <` -> `<=`, `(==|===) || >` -> `>=`, `< || >` -> `!=`, `<= && >=` -> `==`. Operands may appear swapped (the rule inverse-maps the operator), and it ships an autofix that rewrites the whole logical expression to the single suggested comparison.

Source

Thrown at crates/oxc_linter/src/rules/oxc/double_comparisons.rs:10

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

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

fn double_comparisons_diagnostic(span: Span, operator: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected double comparisons.")
        .with_help(format!(
            "This logical expression can be simplified. Try using the `{operator}` operator instead."
        ))
        .with_label(span)
}

/// <https://rust-lang.github.io/rust-clippy/master/index.html#/double_comparisons>
#[derive(Debug, Default, Clone)]
pub struct DoubleComparisons;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// This rule checks for double comparisons in logical expressions.
    ///
    /// ### Why is this bad?
    ///
    /// Redundant comparisons can be confusing and make code harder to understand.

View on GitHub (pinned to 36ec0ef2ba)

Solutions

  1. Replace the pair with the suggested operator: `x <= y`, `x >= y`, `x != y`, or `x == y`
  2. Run `oxlint --fix` — this rule provides a safe automatic fix
  3. Write boundary guards as single comparisons going forward

Example fix

// before
if (x <= y && x >= y) { /* ... */ }

// after
if (x == y) { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — correctness rule, ships an autofix
{
  "rules": { "oxc/double-comparisons": "warn" }
}
// CLI (applies the fix): npx oxlint --fix src/

Prevention

When it happens

Trigger: `x === y || x < y`; `x < y || x > y`; `x <= y && x >= y`; swapped forms such as `x === y || y > x`.

Common situations: Spelling 'less than or equal' as two comparisons out of caution; comparator/sort functions; boundary guards written as comparison pairs.

Related errors


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