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

Inherits:
Cop
  • Object
show all
Includes:
IfThenElse
Defined in:
lib/rubocop/cop/style/one_line_conditional.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, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, #inspect, 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/one_line_conditional.rb', line 14

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

#offending_line(node) ⇒ Object



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

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