Module: RuboCop::Cop::CheckAssignment

Overview

Common functionality for checking assignment nodes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extract_rhs(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/mixin/check_assignment.rb', line 29

def extract_rhs(node)
  if node.casgn_type?
    _scope, _lhs, rhs = *node
  elsif node.op_asgn_type?
    _lhs, _op, rhs = *node
  elsif node.send_type? || node.csend_type?
    rhs = node.last_argument
  elsif node.assignment?
    _lhs, rhs = *node
  end

  rhs
end

Instance Method Details

#on_lvasgn(node) ⇒ Object Also known as: on_ivasgn, on_cvasgn, on_gvasgn, on_casgn, on_masgn, on_op_asgn, on_or_asgn, on_and_asgn



7
8
9
# File 'lib/rubocop/cop/mixin/check_assignment.rb', line 7

def on_lvasgn(node)
  check_assignment(node, extract_rhs(node))
end

#on_send(node) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rubocop/cop/mixin/check_assignment.rb', line 19

def on_send(node)
  rhs = extract_rhs(node)

  return unless rhs

  check_assignment(node, rhs)
end