Class: Rubocop::Cop::Style::WhenThen
- Defined in:
- lib/rubocop/cop/style/when_then.rb
Overview
This cop checks for when; uses in case expressions.
Constant Summary collapse
- MSG =
'Never use "when x;". Use "when x then" instead.'
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, 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
#autocorrect_action(node) ⇒ Object
19 20 21 |
# File 'lib/rubocop/cop/style/when_then.rb', line 19 def autocorrect_action(node) replace(node.loc.begin, ' then') end |
#on_when(node) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/rubocop/cop/style/when_then.rb', line 10 def on_when(node) if node.loc.begin && node.loc.begin.is?(';') add_offence(:convention, node.loc.begin, MSG) do_autocorrect(node) end super end |