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



16
17
18
19
20
21
22
23
# File 'lib/rubocop/cop/style/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/
    if offending_line(node)
      add_offence(:convention, node.loc.expression, error_message)
    end
  end
end

#on_if(node) ⇒ Object



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

def on_if(node)
  check(node)
end

#on_unless(node) ⇒ Object



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

def on_unless(node)
  check(node)
end