Sha256: f6a8957181b58f4a5348ef066f76d0395fd18318aa7f7223c5ec51f8f074dc5c
Contents?: true
Size: 1.22 KB
Versions: 6509
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Style # 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 class WhileUntilDo < Cop MSG = 'Do not use `do` with multi-line `%<keyword>s`.'.freeze def on_while(node) handle(node) end def on_until(node) handle(node) end def handle(node) return unless node.multiline? && node.do? add_offense(node, location: :begin, message: format(MSG, keyword: node.keyword)) end def autocorrect(node) do_range = node.condition.source_range.end.join(node.loc.begin) lambda do |corrector| corrector.remove(do_range) end end end end end end
Version data entries
6,509 entries across 6,503 versions & 25 rubygems