Sha256: 76f76824f25d769b4142e161422f39eec28bcfad4fde9fc6b52ee553264c59a9

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# typed: strict
# frozen_string_literal: true

module Spoom
  module Deadcode
    module Plugins
      class Minitest < Base
        extend T::Sig

        ignore_classes_inheriting_from("Minitest::Test")

        MINITEST_METHODS = T.let(
          Set.new([
            "after_all",
            "around",
            "around_all",
            "before_all",
            "setup",
            "teardown",
          ]),
          T::Set[String],
        )

        sig { override.params(definition: Model::Method).void }
        def on_define_method(definition)
          return unless definition.name.start_with?("test_") || MINITEST_METHODS.include?(definition.name)

          owner = definition.owner
          return unless owner.is_a?(Model::Class)

          @index.ignore(definition) if ignored_subclass?(owner)
        end

        sig { override.params(send: Send).void }
        def on_send(send)
          case send.name
          when "assert_predicate", "refute_predicate"
            name = send.args[1]&.slice
            return unless name

            @index.reference_method(name.delete_prefix(":"), send.location)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spoom-1.4.0 lib/spoom/deadcode/plugins/minitest.rb