Skip to content

binary-operator-with-identical-operands

Rubysuspiciousno fixdefault: warnruby/rubocop

Reports a comparison, logical or bitwise operator (== != === <=> =~ > >= < <= | ^ && ||) whose two sides are the same code (x == x).

The result is constant, or the operand is repeated by mistake: the second one was meant to be another variable.

To fix, correct one operand, or write the constant result.

Reported
...
x == x
a && a
a == b
ruby:
lint:
rules:
binary-operator-with-identical-operands: warn # off, warn (default), error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line binary-operator-with-identical-operands in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/BinaryOperatorWithIdenticalOperands full