Sha256: 0720b0eee38ffaeceffb2d4d9826df1afddb1907843f4b0dda8eb65e9d51c49d

Contents?: true

Size: 1 KB

Versions: 25

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Enforces to use `refute_empty` instead of using `refute(object.empty?)`.
      #
      # @example
      #   # bad
      #   refute(object.empty?)
      #   refute(object.empty?, 'message')
      #
      #   # good
      #   refute_empty(object)
      #   refute_empty(object, 'message')
      #
      class RefuteEmpty < Base
        extend MinitestCopRule

        define_rule :refute, target_method: :empty?

        remove_method :on_send
        def on_send(node)
          return unless node.method?(:refute)
          return unless (arguments = peel_redundant_parentheses_from(node.arguments))
          return unless arguments.first.respond_to?(:method?) && arguments.first.method?(:empty?)
          return unless arguments.first.arguments.empty?

          add_offense(node, message: offense_message(arguments)) do |corrector|
            autocorrect(corrector, node, arguments)
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
rubocop-minitest-0.33.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.32.2 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.32.1 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.32.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.31.1 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.31.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.30.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.29.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.28.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.27.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.26.1 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.26.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.25.1 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.25.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.24.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.23.2 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.23.1 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.23.0 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.22.2 lib/rubocop/cop/minitest/refute_empty.rb
rubocop-minitest-0.22.1 lib/rubocop/cop/minitest/refute_empty.rb