lib/spoom/deadcode/plugins/sorbet.rb in spoom-1.3.2 vs lib/spoom/deadcode/plugins/sorbet.rb in spoom-1.3.3

- old
+ new

@@ -5,35 +5,32 @@ 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) + sig { override.params(definition: Model::Constant).void } + def on_define_constant(definition) + @index.ignore(definition) if sorbet_type_member?(definition) || sorbet_enum_constant?(definition) end - sig { override.params(indexer: Indexer, definition: Definition).void } - def on_define_method(indexer, definition) - definition.ignored! if indexer.last_sig =~ /(override|overridable)/ + sig { override.params(definition: Model::Method).void } + def on_define_method(definition) + @index.ignore(definition) if definition.sigs.any? { |sig| sig.string =~ /(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 + sig { params(definition: Model::Constant).returns(T::Boolean) } + def sorbet_type_member?(definition) + definition.value.match?(/^(type_member|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 + sig { params(definition: Model::Constant).returns(T::Boolean) } + def sorbet_enum_constant?(definition) + owner = definition.owner + return false unless owner.is_a?(Model::Class) + + subclass_of?(owner, "T::Enum") end end end end end