Class: Rubocop::Cop::Style::IfWithSemicolon

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

Overview

Checks for uses of semicolon in if statements.

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from IfThenElse

#check, #on_if, #on_unless

Methods inherited from Cop

#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?

Constructor Details

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

Instance Method Details

#error_messageObject



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

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

#offending_line(node) ⇒ Object



10
11
12
# File 'lib/rubocop/cop/style/if_with_semicolon.rb', line 10

def offending_line(node)
  node.loc.begin.line if node.loc.begin && node.loc.begin.is?(';')
end