Module: RuboCop::Cop::OnNormalIfUnless
Overview
Common functionality for cops checking if and unless expressions.
Instance Method Summary
collapse
Methods included from IfNode
#elsif?, #if_else?, #if_node_parts, #modifier_if?, #ternary?
#def_node_matcher, #def_node_search, #node_search, #node_search_all, #node_search_body, #node_search_first
Instance Method Details
#case_else_clause(node) ⇒ Object
32
33
34
|
# File 'lib/rubocop/cop/mixin/on_normal_if_unless.rb', line 32
def case_else_clause(node)
node.children.last if node.case_type?
end
|
#if_else_clause(node) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rubocop/cop/mixin/on_normal_if_unless.rb', line 19
def if_else_clause(node)
return unless node.if_type?
keyword = node.loc.keyword
if keyword.is?('if')
node.children.last
elsif keyword.is?('elsif')
node.children.last
elsif keyword.is?('unless')
node.children[1]
end
end
|
#invoke_hook_for_normal_if_unless(node) ⇒ Object
13
14
15
16
17
|
# File 'lib/rubocop/cop/mixin/on_normal_if_unless.rb', line 13
def invoke_hook_for_normal_if_unless(node)
return if modifier_if?(node) || ternary?(node)
on_normal_if_unless(node)
end
|
#on_if(node) ⇒ Object
9
10
11
|
# File 'lib/rubocop/cop/mixin/on_normal_if_unless.rb', line 9
def on_if(node)
invoke_hook_for_normal_if_unless(node)
end
|