class RuboCop::Cop::Style::MultilineIfThen

Checks for uses of the `then` keyword in multi-line if statements.

@example This is considered bad practice:

if cond then
end

@example If statements can contain `then` on the same line:

if cond then a
elsif cond then b
end

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 32
def autocorrect(node)
  lambda do |corrector|
    corrector.remove(range_with_surrounding_space(node.loc.begin,
                                                  :left))
  end
end
message(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 28
def message(node)
  "Do not use `then` for multi-line `#{node.loc.keyword.source}`."
end
on_normal_if_unless(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 22
def on_normal_if_unless(node)
  return unless node.loc.begin
  return unless node.loc.begin.source_line =~ /then\s*(#.*)?$/
  add_offense(node, :begin)
end