Sha256: 090b99b951a45c16f2c5a7688f1ee8f08da577c1abe28166dffcb8fb689e6f8d

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # This cop enforces the test to use `assert_empty`
      # instead of using `assert(object.empty?)`.
      #
      # @example
      #   # bad
      #   assert(object.empty?)
      #   assert(object.empty?, 'message')
      #
      #   # good
      #   assert_empty(object)
      #   assert_empty(object, 'message')
      #
      class AssertEmpty < Base
        extend MinitestCopRule

        define_rule :assert, target_method: :empty?

        remove_method :on_send
        def on_send(node)
          return unless node.method?(:assert)
          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

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-minitest-0.19.1 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.19.0 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.18.0 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.17.2 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.17.1 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.17.0 lib/rubocop/cop/minitest/assert_empty.rb
rubocop-minitest-0.16.0 lib/rubocop/cop/minitest/assert_empty.rb