Sha256: 8cf24df517849f57537fd75cfad3e24594a6272512f60b78186785b007c49642

Contents?: true

Size: 866 Bytes

Versions: 3

Compression:

Stored size: 866 Bytes

Contents

# typed: strict
# frozen_string_literal: true

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

        sig { override.params(indexer: Indexer, definition: Definition).void }
        def on_define_class(indexer, definition)
          definition.ignored! if used_as_namespace?(indexer)
        end

        sig { override.params(indexer: Indexer, definition: Definition).void }
        def on_define_module(indexer, definition)
          definition.ignored! if used_as_namespace?(indexer)
        end

        private

        sig { params(indexer: Indexer).returns(T::Boolean) }
        def used_as_namespace?(indexer)
          node = indexer.current_node
          return false unless node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode)

          !!node.body
        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/namespaces.rb
spoom-1.3.1 lib/spoom/deadcode/plugins/namespaces.rb
spoom-1.3.0 lib/spoom/deadcode/plugins/namespaces.rb