Skip to content

Commit

Permalink
Pass SymbolDefs to plugin on_class
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jun 20, 2024
1 parent 9eefe03 commit 49c816f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions lib/spoom/deadcode/plugins/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,26 @@ def internal_on_define_accessor(indexer, definition)
#
# ~~~rb
# class MyPlugin < Spoom::Deadcode::Plugins::Base
# def on_define_class(indexer, definition)
# definition.ignored! if definition.name == "Foo"
# def on_define_class(symbol_def, definition)
# definition.ignored! if symbol_def.name == "Foo"
# end
# end
# ~~~
sig { params(indexer: Indexer, definition: Definition).void }
def on_define_class(indexer, definition)
sig { params(symbol_def: Model::Class, definition: Definition).void }
def on_define_class(symbol_def, definition)
# no-op
end

# Do not override this method, use `on_define_class` instead.
sig { params(indexer: Indexer, definition: Definition).void }
def internal_on_define_class(indexer, definition)
if ignored_class_name?(definition.name)
sig { params(symbol_def: Model::Class, definition: Definition).void }
def internal_on_define_class(symbol_def, definition)
if ignored_class_name?(symbol_def.name)
definition.ignored!
elsif ignored_subclass?(indexer.nesting_class_superclass_name)
elsif ignored_subclass?(symbol_def.superclass_name&.delete_prefix("::"))
definition.ignored!
end

on_define_class(indexer, definition)
on_define_class(symbol_def, definition)
end

# Called when a constant is defined.
Expand Down
6 changes: 3 additions & 3 deletions lib/spoom/deadcode/plugins/namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ 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)
sig { override.params(symbol_def: Model::Class, definition: Definition).void }
def on_define_class(symbol_def, definition)
definition.ignored! unless symbol_def.children.empty?
end

sig { override.params(indexer: Indexer, definition: Definition).void }
Expand Down
6 changes: 3 additions & 3 deletions lib/spoom/deadcode/plugins/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Rails < Base

ignore_constants_named("APP_PATH", "ENGINE_PATH", "ENGINE_ROOT")

sig { override.params(indexer: Indexer, definition: Definition).void }
def on_define_class(indexer, definition)
definition.ignored! if file_is_helper?(indexer)
sig { override.params(symbol_def: Model::Class, definition: Definition).void }
def on_define_class(symbol_def, definition)
definition.ignored! if symbol_def.location.file.match?(%r{app/helpers/.*\.rb$})
end

sig { override.params(indexer: Indexer, definition: Definition).void }
Expand Down
4 changes: 2 additions & 2 deletions test/spoom/deadcode/plugins/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def on_define_accessor(indexer, definition)

def test_on_define_class
plugin = Class.new(Base) do
def on_define_class(indexer, definition)
definition.ignored! if definition.name == "Class1"
def on_define_class(symbol_def, definition)
definition.ignored! if symbol_def.name == "Class1"
end
end

Expand Down

0 comments on commit 49c816f

Please sign in to comment.