{"record":{"id":"f5265d4e1bc2eed6","repo":"oxc-project/oxc","slug":"unexpected-double-comparisons","errorCode":null,"errorMessage":"Unexpected double comparisons.","messagePattern":"Unexpected double comparisons\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/oxc/double_comparisons.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::{BinaryOperator, LogicalOperator};\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_same_expression};\n\nfn double_comparisons_diagnostic(span: Span, operator: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected double comparisons.\")\n        .with_help(format!(\n            \"This logical expression can be simplified. Try using the `{operator}` operator instead.\"\n        ))\n        .with_label(span)\n}\n\n/// <https://rust-lang.github.io/rust-clippy/master/index.html#/double_comparisons>\n#[derive(Debug, Default, Clone)]\npub struct DoubleComparisons;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule checks for double comparisons in logical expressions.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Redundant comparisons can be confusing and make code harder to understand.","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/36ec0ef2bae567d1a8413ada2fe795f1af1f2785/crates/oxc_linter/src/rules/oxc/double_comparisons.rs#L1-L28","documentation":"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.","triggerScenarios":"`x === y || x < y`; `x < y || x > y`; `x <= y && x >= y`; swapped forms such as `x === y || y > x`.","commonSituations":"Spelling 'less than or equal' as two comparisons out of caution; comparator/sort functions; boundary guards written as comparison pairs.","solutions":["Replace the pair with the suggested operator: `x <= y`, `x >= y`, `x != y`, or `x == y`","Run `oxlint --fix` — this rule provides a safe automatic fix","Write boundary guards as single comparisons going forward"],"exampleFix":"// before\nif (x <= y && x >= y) { /* ... */ }\n\n// after\nif (x == y) { /* ... */ }","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — correctness rule, ships an autofix\n{\n  \"rules\": { \"oxc/double-comparisons\": \"warn\" }\n}\n// CLI (applies the fix): npx oxlint --fix src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `x <= y` directly instead of `x === y || x < y`","Run `oxlint --fix` after editing comparison chains","In comparators, prefer single comparison operators over logical pairs"],"tags":["oxlint","oxc","comparison","simplification","javascript","static-analysis"],"backgroundTag":"simplifiable-double-comparison","analyzedSha":"36ec0ef2bae567d1a8413ada2fe795f1af1f2785","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}