Sha256: 7ecb2df0d4ce3ec58ac4e4c2003d902ebc31e09c32ac305cb6dcb4ebe84826a4

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Enforces the use of `refute_instance_of(Class, object)`
      # over `refute(object.instance_of?(Class))`.
      #
      # @example
      #   # bad
      #   refute(object.instance_of?(Class))
      #   refute(object.instance_of?(Class), 'message')
      #
      #   # bad
      #   refute_equal(Class, object.class)
      #   refute_equal(Class, object.class, 'message')
      #
      #   # good
      #   refute_instance_of(Class, object)
      #   refute_instance_of(Class, object, 'message')
      #
      class RefuteInstanceOf < Base
        include InstanceOfAssertionHandleable
        extend AutoCorrector

        RESTRICT_ON_SEND = %i[refute refute_equal].freeze

        def_node_matcher :instance_of_assertion?, <<~PATTERN
          {
            (send nil? :refute (send $_ :instance_of? $const) $_?)
            (send nil? :refute_equal $const (send $_ :class) $_?)
          }
        PATTERN

        def on_send(node)
          investigate(node, :refute)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubocop-minitest-0.36.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.35.1 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.35.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.5 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.4 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.3 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.2 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.1 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.34.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.33.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.32.2 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.32.1 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.32.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.31.1 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.31.0 lib/rubocop/cop/minitest/refute_instance_of.rb
rubocop-minitest-0.30.0 lib/rubocop/cop/minitest/refute_instance_of.rb