forked from rubocop/rubocop
/
check_assignment.rb
44 lines (37 loc) · 1012 Bytes
/
check_assignment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true
module RuboCop
module Cop
# Common functionality for checking assignment nodes.
module CheckAssignment
def on_lvasgn(node)
check_assignment(node, extract_rhs(node))
end
alias on_ivasgn on_lvasgn
alias on_cvasgn on_lvasgn
alias on_gvasgn on_lvasgn
alias on_casgn on_lvasgn
alias on_masgn on_lvasgn
alias on_op_asgn on_lvasgn
alias on_or_asgn on_lvasgn
alias on_and_asgn on_lvasgn
def on_send(node)
rhs = extract_rhs(node)
return unless rhs
check_assignment(node, rhs)
end
module_function
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
end
end
end