For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-double-comparison.md.
close

no-double-comparison

Unreleased

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-double-comparison': 'error',
    },
  },
]);

Rule Details

Disallow two comparisons of the same operands that can be combined into one. Operands may appear in either order; the suggestion retains the first comparison's operand order.

Examples of incorrect code:

x === y || x < y;
x === y || x > y;
x < y || x > y;
x <= y && x >= y;
x <= y && x !== y;
x >= y && x !== y;
x === y || y < x;

Examples of correct code:

x <= y;
x >= y;
x !== y;
x === y;
x < y;
x > y;

Suggestions

The rule offers editor suggestions. Combining comparisons can change behavior for mixed types, NaN, undefined, symbols, or objects with getters or custom coercion. Review the suggestion before applying it. For example, undefined === undefined || undefined < undefined is true, while undefined <= undefined is false.

Loose equality, optional chains, known regular-expression operands and comparisons with different operands are ignored. Longer logical chains are checked pairwise. A diagnostic has no suggestion when replacing it would discard a comment; comments inside the retained operands are preserved.

Options

This rule has no options.

Original Documentation