module RuboCop::Cop::CheckAssignment

Common functionality for checking assignment nodes.

Public Instance Methods

extract_rhs(node) click to toggle source
# File lib/rubocop/cop/mixin/check_assignment.rb, line 25
def extract_rhs(node)
  if node.casgn_type?
    _scope, _lhs, rhs = *node
  elsif node.op_asgn_type?
    _lhs, _op, rhs = *node
  elsif Util::ASGN_NODES.include?(node.type)
    _lhs, rhs = *node
  elsif node.send_type?
    rhs = node.children.last
  end

  rhs
end
on_send(node) click to toggle source
# File lib/rubocop/cop/mixin/check_assignment.rb, line 13
def on_send(node)
  # we only want to indent relative to the receiver
  # when the method called looks like a setter
  return unless node.asgn_method_call?

  # This will match if, case, begin, blocks, etc.
  rhs = extract_rhs(node)
  check_assignment(node, rhs) if rhs.is_a?(AST::Node)
end