Module: RuboCop::Cop::CheckAssignment

Included in:
Lint::BlockAlignment, Lint::EndAlignment, Style::ElseAlignment, Style::IndentationWidth
Defined in:
lib/rubocop/cop/mixin/check_assignment.rb

Overview

Common functionality for checking assignment nodes.

Constant Summary collapse

TYPES =
Util::ASGN_NODES - [:casgn, :op_asgn]

Instance Method Summary collapse

Instance Method Details

#on_casgn(node) ⇒ Object



15
16
17
18
# File 'lib/rubocop/cop/mixin/check_assignment.rb', line 15

def on_casgn(node)
  _scope, _lhs, rhs = *node
  check_assignment(node, rhs)
end

#on_op_asgn(node) ⇒ Object



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

def on_op_asgn(node)
  _lhs, _op, rhs = *node
  check_assignment(node, rhs)
end

#on_send(node) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/mixin/check_assignment.rb', line 25

def on_send(node)
  _receiver, method_name, *_, rhs = *node

  # we only want to indent relative to the receiver
  # when the method called looks like a setter
  return unless method_name.to_s.end_with?('=')

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