Module: Rubocop::Cop::Style::IfThenElse

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

Overview

Common functionality for cops checking if and unless statements.

Instance Method Summary collapse

Instance Method Details

#check(node) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rubocop/cop/style/if_then_else.rb', line 18

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

#on_if(node) ⇒ Object



8
9
10
11
# File 'lib/rubocop/cop/style/if_then_else.rb', line 8

def on_if(node)
  check(node)
  super
end

#on_unless(node) ⇒ Object



13
14
15
16
# File 'lib/rubocop/cop/style/if_then_else.rb', line 13

def on_unless(node)
  check(node)
  super
end