class RuboCop::Cop::Style::WhileUntilDo

Checks for uses of `do` in multi-line `while/until` statements.

Public Instance Methods

handle(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 16
def handle(node)
  length = node.source.lines.to_a.size
  return unless length > 1
  return unless node.loc.begin && node.loc.begin.is?('do')

  add_offense(node, :begin, error_message(node.type))
end
on_until(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 12
def on_until(node)
  handle(node)
end
on_while(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 8
def on_while(node)
  handle(node)
end

Private Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 30
def autocorrect(node)
  condition_node, = *node
  end_of_condition_range = condition_node.source_range.end
  do_range = node.loc.begin
  whitespaces_and_do_range = end_of_condition_range.join(do_range)
  ->(corrector) { corrector.remove(whitespaces_and_do_range) }
end
error_message(node_type) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 26
def error_message(node_type)
  format('Do not use `do` with multi-line `%s`.', node_type)
end