class RuboCop::Cop::Style::MultilineIfThen

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

@example

# bad
# This is considered bad practice.
if cond then
end

# good
# If statements can contain `then` on the same line.
if cond then a
elsif cond then b
end

Constants

MSG
NON_MODIFIER_THEN

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 34
def autocorrect(node)
  lambda do |corrector|
    corrector.remove(
      range_with_surrounding_space(range: node.loc.begin, side: :left)
    )
  end
end
on_normal_if_unless(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 27
def on_normal_if_unless(node)
  return unless non_modifier_then?(node)

  add_offense(node, location: :begin,
                    message: format(MSG, keyword: node.keyword))
end

Private Instance Methods

non_modifier_then?(node) click to toggle source
# File lib/rubocop/cop/style/multiline_if_then.rb, line 44
def non_modifier_then?(node)
  node.loc.begin && node.loc.begin.source_line =~ NON_MODIFIER_THEN
end