Sha256: 14e117fcf236940a8c39222dedf22fdf95db35c5dfc5495d0c5933b0d1650eec

Contents?: true

Size: 930 Bytes

Versions: 6894

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for uses of while with a negated condition.
      #
      # @example
      #   # bad
      #   while !foo
      #     bar
      #   end
      #
      #   # good
      #   until foo
      #     bar
      #   end
      #
      #   # bad
      #   bar until !foo
      #
      #   # good
      #   bar while foo
      #   bar while !foo && baz
      class NegatedWhile < Cop
        include NegativeConditional

        def on_while(node)
          check_negative_conditional(node)
        end

        def on_until(node)
          check_negative_conditional(node)
        end

        def autocorrect(node)
          ConditionCorrector.correct_negative_condition(node)
        end

        private

        def message(node)
          format(MSG, inverse: node.inverse_keyword, current: node.keyword)
        end
      end
    end
  end
end

Version data entries

6,894 entries across 6,869 versions & 30 rubygems

Version Path
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/negated_while.rb
rubocop-0.60.0 lib/rubocop/cop/style/negated_while.rb
rubocop-0.59.2 lib/rubocop/cop/style/negated_while.rb
rubocop-0.59.1 lib/rubocop/cop/style/negated_while.rb
rubocop-0.59.0 lib/rubocop/cop/style/negated_while.rb
rubocop-0.58.2 lib/rubocop/cop/style/negated_while.rb
rubocop-0.58.1 lib/rubocop/cop/style/negated_while.rb
rubocop-0.58.0 lib/rubocop/cop/style/negated_while.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/negated_while.rb
rubocop-0.57.2 lib/rubocop/cop/style/negated_while.rb
rubocop-0.57.1 lib/rubocop/cop/style/negated_while.rb
rubocop-0.57.0 lib/rubocop/cop/style/negated_while.rb
rubocop-0.56.0 lib/rubocop/cop/style/negated_while.rb
rubocop-0.55.0 lib/rubocop/cop/style/negated_while.rb