Class: Rubocop::Cop::IfWithSemicolon

Inherits:
Cop
  • Object
show all
Includes:
IfThenElse
Defined in:
lib/rubocop/cop/if_then_else.rb

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from IfThenElse

#check, #on_if, #on_unless

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#error_messageObject



34
35
36
# File 'lib/rubocop/cop/if_then_else.rb', line 34

def error_message
  'Never use if x; Use the ternary operator instead.'
end

#offending_line(node) ⇒ Object



28
29
30
31
32
# File 'lib/rubocop/cop/if_then_else.rb', line 28

def offending_line(node)
  if node.loc.begin && node.loc.begin.source == ';'
    node.loc.begin.line
  end
end