Sha256: ac312bacdb03efae9978a6413be4217cad59161fea36e37ca5334d2f9d843a4a

Contents?: true

Size: 1.06 KB

Versions: 255

Compression:

Stored size: 1.06 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 < 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

255 entries across 246 versions & 24 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/while_until_do.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/while_until_do.rb
rubocop-1.65.0 lib/rubocop/cop/style/while_until_do.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/while_until_do.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/while_until_do.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/while_until_do.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/while_until_do.rb
rubocop-1.64.1 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.63.4 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.63.3 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.63.2 lib/rubocop/cop/style/while_until_do.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/while_until_do.rb
rubocop-1.63.1 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.63.0 lib/rubocop/cop/style/while_until_do.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/style/while_until_do.rb
rubocop-1.62.1 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.62.0 lib/rubocop/cop/style/while_until_do.rb
rubocop-1.61.0 lib/rubocop/cop/style/while_until_do.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.2/lib/rubocop/cop/style/while_until_do.rb
rubocop-1.60.2 lib/rubocop/cop/style/while_until_do.rb