Class: Rubocop::Cop::CaseIndentation

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/case_indentation.rb

Constant Summary collapse

MSG =
'Indent when as deep as case.'

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

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

Instance Method Details

#on_case(case_node) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/cop/case_indentation.rb', line 8

def on_case(case_node)
  _condition, *whens, _else = *case_node

  case_column = case_node.location.keyword.column

  whens.each do |when_node|
    pos = when_node.loc.keyword
    add_offence(:convention, pos.line, MSG) if pos.column != case_column
  end

  super
end