Sha256: 0295dac811ef4a2f7d4bd3e4a9f27d0f89a9114dd512c7e40eb6616f77541e58

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

# typed: strict
# frozen_string_literal: true

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

        sig { override.params(indexer: Indexer, definition: Definition).void }
        def on_define_constant(indexer, definition)
          definition.ignored! if sorbet_type_member?(indexer, definition) || sorbet_enum_constant?(indexer, definition)
        end

        sig { override.params(indexer: Indexer, definition: Definition).void }
        def on_define_method(indexer, definition)
          definition.ignored! if indexer.last_sig =~ /(override|overridable)/
        end

        private

        sig { params(indexer: Indexer, definition: Definition).returns(T::Boolean) }
        def sorbet_type_member?(indexer, definition)
          assign = indexer.nesting_node(Prism::ConstantWriteNode)
          return false unless assign

          value = assign.value
          return false unless value.is_a?(Prism::CallNode)

          value.name == :type_member || value.name == :type_template
        end

        sig { params(indexer: Indexer, definition: Definition).returns(T::Boolean) }
        def sorbet_enum_constant?(indexer, definition)
          /^(::)?T::Enum$/.match?(indexer.nesting_class_superclass_name) && indexer.nesting_call&.name == :enums
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spoom-1.3.2 lib/spoom/deadcode/plugins/sorbet.rb
spoom-1.3.1 lib/spoom/deadcode/plugins/sorbet.rb
spoom-1.3.0 lib/spoom/deadcode/plugins/sorbet.rb