class RuboCop::Cop::Style::NegatedWhile

Checks for uses of while with a negated condition.

@example

# bad
while !foo
  bar
end

# good
until foo
  bar
end

# bad
bar until !foo

# good
bar while foo
bar while !foo && baz

Public Instance Methods

on_until(node)
Alias for: on_while
on_while(node) click to toggle source
# File lib/rubocop/cop/style/negated_while.rb, line 29
def on_while(node)
  message = format(MSG, inverse: node.inverse_keyword, current: node.keyword)

  check_negative_conditional(node, message: message) do |corrector|
    ConditionCorrector.correct_negative_condition(corrector, node)
  end
end
Also aliased as: on_until