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, #corrections, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#autocorrect_action(node) ⇒ Object
17 18 19 20 21 |
# File 'lib/rubocop/cop/style/when_then.rb', line 17 def autocorrect_action(node) @corrections << lambda do |corrector| corrector.replace(node.loc.begin, ' then') end end |
#on_when(node) ⇒ Object
10 11 12 13 14 15 |
# 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 end |