class RuboCop::Cop::Lint::AmbiguousAssignment
x != y # or x = !y
x *= y # or x = *y
x += y # or x = +y
x -= y # or x = -y
# good
x =! y
x =* y
x =+ y
x =- y
# bad
@example
Checks for mistyped shorthand assignments.
def on_asgn(node)
def on_asgn(node) return unless (rhs = rhs(node)) range = range_between(node.loc.operator.end_pos - 1, rhs.source_range.begin_pos + 1) source = range.source return unless MISTAKES.key?(source) add_offense(range, message: format(MSG, op: MISTAKES[source])) end
def rhs(node)
def rhs(node) if node.casgn_type? node.children[2] else node.children[1] end end