Class: Rubocop::Cop::Style::CaseIndentation
- Defined in:
- lib/rubocop/cop/style/case_indentation.rb
Overview
This cop checks whether the when*s of a *case expression are indented as deep as its case keyword.
It will register a separate offence for each misaligned when.
Constant Summary collapse
- MSG =
'Indent when as deep as case.'
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #autocorrect_action, #convention, #cop_config, #cop_name, cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, rails?, style?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#on_case(case_node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubocop/cop/style/case_indentation.rb', line 13 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 convention(when_node, pos) if pos.column != case_column end end |