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 20
def handle(node)
  length = node.loc.expression.source.lines.to_a.size

  if length > 1
    if node.loc.begin && node.loc.begin.is?('do')
      add_offence(:convention,
                  node.loc.begin,
                  error_message(node.type))
      do_autocorrect(node)
    end
  end
end
on_until(node) click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/while_until_do.rb, line 14
def on_until(node)
  handle(node)

  super
end
on_while(node) click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/while_until_do.rb, line 8
def on_while(node)
  handle(node)

  super
end

Private Instance Methods

autocorrect_action(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 39
def autocorrect_action(node)
  remove(node.loc.begin)
end
error_message(node_type) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 35
def error_message(node_type)
  format('Never use `do` with multi-line `%s`.', node_type)
end