Sha256: b8bc4923e04ea38ea98a12b4f86f48eec7f63d9e4d88f82af9da0fcf0b0463d5
Contents?: true
Size: 1.04 KB
Versions: 9
Compression:
Stored size: 1.04 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 # # # bad # until x.empty? do # do_something(x.pop) # end # # # good # until x.empty? # do_something(x.pop) # end class WhileUntilDo < Base extend AutoCorrector MSG = 'Do not use `do` with multi-line `%<keyword>s`.' 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 alias on_until on_while end end end end
Version data entries
9 entries across 9 versions & 1 rubygems