Class: RuboCop::Cop::Style::MultilineWhenThen

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/style/multiline_when_then.rb

Overview

Checks uses of the ‘then` keyword in multi-line when statements.

Examples:

# bad
case foo
when bar then
end

# good
case foo
when bar
end

# good
case foo
when bar then do_something
end

# good
case foo
when bar then do_something(arg1,
                           arg2)
end

Constant Summary collapse

MSG =
'Do not use `then` for multiline `when` statement.'

Instance Method Summary collapse

Methods included from AutoCorrector

support_autocorrect?

Instance Method Details

#on_when(node) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rubocop/cop/style/multiline_when_then.rb', line 37

def on_when(node)
  return if !node.then? || require_then?(node)

  range = node.loc.begin
  add_offense(range) do |corrector|
    corrector.remove(range_with_surrounding_space(range, side: :left, newlines: false))
  end
end