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.

Constant Summary

Constants inherited from Cop

Cop::OPERATOR_METHODS

Instance Attribute Summary

Attributes inherited from Cop

#config, #corrections, #offences, #processed_source

Instance Method Summary collapse

Methods included from IfThenElse

#check, #on_if, #on_unless

Methods inherited from Cop

#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, non_rails, rails?, style?, #support_autocorrect?, #warning

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