Sha256: d225d3ecb765ca9abeadd1820485e5ad7caa609227c47582f84e9356a1eaaed9

Contents?: true

Size: 958 Bytes

Versions: 9

Compression:

Stored size: 958 Bytes

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)`.
      #
      # @example
      #   # bad
      #   assert([], object)
      #   assert({}, object)
      #
      #   # good
      #   assert_empty(object)
      #
      class AssertEmptyLiteral < Cop
        MSG = 'Prefer using `assert_empty(%<arguments>s)` over ' \
              '`assert(%<literal>s, %<arguments>s)`.'

        def_node_matcher :assert_with_empty_literal, <<~PATTERN
          (send nil? :assert ${hash array} $...)
        PATTERN

        def on_send(node)
          assert_with_empty_literal(node) do |literal, matchers|
            args = matchers.map(&:source).join(', ')

            message = format(MSG, literal: literal.source, arguments: args)
            add_offense(node, message: message)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-minitest-0.9.0 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.8.1 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.8.0 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.7.0 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.6.2 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.6.1 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.6.0 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.5.1 lib/rubocop/cop/minitest/assert_empty_literal.rb
rubocop-minitest-0.5.0 lib/rubocop/cop/minitest/assert_empty_literal.rb