class RuboCop::Cop::Lint::BinaryOperatorWithIdenticalOperands


1 << 1
x + x
# good
end
left_child || left_child
def child?
end
do_something
if a.x != 0 && a.x != 0
x.top >= x.top
x / x
# bad
@example
—-
end
# …
if wr.take_char == ‘0’ && wr.take_char == ‘0’
—-
[source,ruby]

and thus can generate false positives, for example:
This cop is unsafe as it does not consider side effects when calling methods
@safety
thus are legitimate offenses.
always be the same (‘x - x` will always be 0; `x / x` will always be 1), and
do so. This does not include operations such as `-` or `/` where the result will
Although these can be rewritten in a different way, it should not be necessary to
Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`, `<<` and `>>`.
and “spaceship” operator - `<=>`.
boolean operators: `&&`, `||`
bitwise operators: `|`, `^`, `&`;
comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`;
It covers arithmetic operators: `-`, `/`, `%`;
Checks for places where binary operator has identical operands.

def on_and(node)

def on_and(node)
  add_offense(node, message: format(MSG, op: node.operator)) if node.lhs == node.rhs
end

def on_send(node)

def on_send(node)
  return unless node.binary_operation?
  lhs, operation, rhs = *node
  return if ALLOWED_MATH_OPERATORS.include?(node.method_name)
  add_offense(node, message: format(MSG, op: operation)) if lhs == rhs
end