Module: Rubocop::Cop::IfThenElse

Included in:
IfWithSemicolon, MultilineIfThen, OneLineConditional
Defined in:
lib/rubocop/cop/if_then_else.rb

Instance Method Summary collapse

Instance Method Details

#check(node) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rubocop/cop/if_then_else.rb', line 16

def check(node)
  # We won't check modifier or ternary conditionals.
  if node.loc.expression.source =~ /\A(if|unless)\b/
    line = offending_line(node)
    add_offence(:convention, line, error_message) if line
  end
end

#on_if(node) ⇒ Object



6
7
8
9
# File 'lib/rubocop/cop/if_then_else.rb', line 6

def on_if(node)
  check(node)
  super
end

#on_unless(node) ⇒ Object



11
12
13
14
# File 'lib/rubocop/cop/if_then_else.rb', line 11

def on_unless(node)
  check(node)
  super
end