Class: Rubocop::Cop::Style::OneLineConditional

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

Overview

Checks for uses of if/then/else/end on a single line.

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods included from IfThenElse

#check, #on_if, #on_unless

Methods inherited from Cop

#add_offence, #autocorrect_action, cop_name, #do_autocorrect, #ignore_node, inherited, #initialize, #inspect, #name, rails?

Constructor Details

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

Instance Method Details

#error_messageObject



74
75
76
# File 'lib/rubocop/cop/style/if_then_else.rb', line 74

def error_message
  'Favor the ternary operator (?:) over if/then/else/end constructs.'
end

#offending_line(node) ⇒ Object



70
71
72
# File 'lib/rubocop/cop/style/if_then_else.rb', line 70

def offending_line(node)
  node.loc.expression.line unless node.loc.expression.source =~ /\n/
end