lib/rubocop/cop/style/while_until_do.rb in rubocop-0.46.0 vs lib/rubocop/cop/style/while_until_do.rb in rubocop-0.47.0

- old
+ new

@@ -3,37 +3,33 @@ module RuboCop module Cop module Style # Checks for uses of `do` in multi-line `while/until` statements. class WhileUntilDo < Cop + MSG = 'Do not use `do` with multi-line `%s`.'.freeze + def on_while(node) handle(node) end def on_until(node) handle(node) end def handle(node) - length = node.source.lines.to_a.size - return unless length > 1 - return unless node.loc.begin && node.loc.begin.is?('do') + return unless node.multiline? && node.do? - add_offense(node, :begin, error_message(node.type)) + add_offense(node, :begin, format(MSG, node.keyword)) end private - def error_message(node_type) - format('Do not use `do` with multi-line `%s`.', node_type) - end - 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) } + do_range = node.condition.source_range.end.join(node.loc.begin) + + lambda do |corrector| + corrector.remove(do_range) + end end end end end end