class RuboCop::Cop::Style::WhileUntilDo

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

@example

# bad
while x.any? do
  do_something(x.pop)
end

# good
while x.any?
  do_something(x.pop)
end

@example

# bad
until x.empty? do
  do_something(x.pop)
end

# good
until x.empty?
  do_something(x.pop)
end

Constants

MSG

Public Instance Methods

on_until(node)
Alias for: on_while
on_while(node) click to toggle source
# File lib/rubocop/cop/style/while_until_do.rb, line 36
def on_while(node)
  return unless node.multiline? && node.do?

  add_offense(node.loc.begin, message: format(MSG, keyword: node.keyword)) do |corrector|
    do_range = node.condition.source_range.end.join(node.loc.begin)

    corrector.remove(do_range)
  end
end
Also aliased as: on_until