Class: Rubocop::Cop::MultilineIfThen
- 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
Methods inherited from Cop
#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #inspect, #name
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#error_message ⇒ Object
58 59 60 |
# File 'lib/rubocop/cop/if_then_else.rb', line 58 def 'Never use then for multi-line if/unless.' end |
#offending_line(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/if_then_else.rb', line 42 def offending_line(node) condition, body = *node next_thing = if body && body.loc.expression body.loc.expression.begin else node.loc.end # No body, use "end". end right_after_cond = Parser::Source::Range.new(next_thing.source_buffer, condition.loc.expression.end.end_pos, next_thing.begin_pos) if right_after_cond.source =~ /\A\s*then\s*(#.*)?\s*\n/ node.loc.expression.begin.line end end |