class RuboCop::Cop::Style::WhileUntilModifier
x += 1 until x > 10
# good
end
x += 1
until x > 10
# bad
@example
x += 1 while x < 10
# good
end
x += 1
while x < 10
# bad
@example
configured in the ‘Metrics/LineLength` cop.
if written as a modifier while/until. The maximum line length is
Checks for while and until statements that would fit on one line
def autocorrect(node)
def autocorrect(node) oneline = "#{node.body.source} #{node.keyword} " \ "#{node.condition.source}" lambda do |corrector| corrector.replace(node.source_range, oneline) end end
def check(node)
def check(node) return unless node.multiline? && single_line_as_modifier?(node) add_offense(node, location: :keyword, message: format(MSG, keyword: node.keyword)) end
def on_until(node)
def on_until(node) check(node) end
def on_while(node)
def on_while(node) check(node) end