Sha256: 601b637fe32d3f5cd88d6be5ca15bc914297e1588e0855d0342885dc866c1156

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for uses of `begin...end while/until something`.
      #
      # @example
      #
      #   # bad
      #
      #   # using while
      #   begin
      #     do_something
      #   end while some_condition
      #
      # @example
      #
      #   # bad
      #
      #   # using until
      #   begin
      #     do_something
      #   end until some_condition
      #
      # @example
      #
      #   # good
      #
      #   # while replacement
      #   loop do
      #     do_something
      #     break unless some_condition
      #   end
      #
      # @example
      #
      #   # good
      #
      #   # until replacement
      #   loop do
      #     do_something
      #     break if some_condition
      #   end
      class Loop < Cop
        MSG = 'Use `Kernel#loop` with `break` rather than ' \
              '`begin/end/until`(or `while`).'

        def on_while_post(node)
          register_offense(node)
        end

        def on_until_post(node)
          register_offense(node)
        end

        private

        def register_offense(node)
          add_offense(node, location: :keyword)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/loop.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/loop.rb
rubocop-0.87.1 lib/rubocop/cop/lint/loop.rb
rubocop-0.87.0 lib/rubocop/cop/lint/loop.rb
rubocop-0.86.0 lib/rubocop/cop/lint/loop.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/loop.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/loop.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/loop.rb
rubocop-0.85.1 lib/rubocop/cop/lint/loop.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/loop.rb
rubocop-0.85.0 lib/rubocop/cop/lint/loop.rb