Skip to content

Commit

Permalink
Do not pass indexer to plugin on_send
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jun 19, 2024
1 parent 8035cc4 commit 108d6fd
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/spoom/deadcode/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def visit_send(send)
visit(send.recv)

@plugins.each do |plugin|
plugin.internal_on_send(self, send)
plugin.on_send(send)
end

@index.reference_method(send.name, send.location)
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Plugins
class ActionMailer < Base
extend T::Sig

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
return unless send.recv.nil? && ActionPack::CALLBACKS.include?(send.name)

send.each_arg(Prism::SymbolNode) do |arg|
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/actionpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def on_define_method(symbol_def, definition)
definition.ignored! if ignored_class_name?(owner.name)
end

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
return unless send.recv.nil? && CALLBACKS.include?(send.name)

arg = send.args.first
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/active_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ActiveModel < Base
ignore_classes_inheriting_from(/^(::)?ActiveModel::EachValidator$/)
ignore_methods_named("validate_each")

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
return if send.recv

case send.name
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class ActiveRecord < Base
T::Array[String],
)

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
if send.recv.nil? && CALLBACKS.include?(send.name)
send.each_arg(Prism::SymbolNode) do |arg|
@index.reference_method(arg.unescaped, send.location)
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ActiveSupport < Base

SETUP_AND_TEARDOWN_METHODS = T.let(["setup", "teardown"], T::Array[String])

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
return unless send.recv.nil? && SETUP_AND_TEARDOWN_METHODS.include?(send.name)

send.each_arg(Prism::SymbolNode) do |arg|
Expand Down
10 changes: 2 additions & 8 deletions lib/spoom/deadcode/plugins/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,11 @@ def internal_on_define_module(symbol_def, definition)
# end
# end
# ~~~
sig { params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { params(send: Send).void }
def on_send(send)
# no-op
end

# Do not override this method, use `on_send` instead.
sig { params(indexer: Indexer, send: Send).void }
def internal_on_send(indexer, send)
on_send(indexer, send)
end

private

# DSL support
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class GraphQL < Base
"unsubscribed",
)

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
return unless send.recv.nil? && send.name == "field"

arg = send.args.first
Expand Down
4 changes: 2 additions & 2 deletions lib/spoom/deadcode/plugins/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Ruby < Base
"to_s",
)

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
sig { override.params(send: Send).void }
def on_send(send)
case send.name
when "const_defined?", "const_get", "const_source_location"
reference_symbol_as_constant(send, T.must(send.args.first))
Expand Down
2 changes: 1 addition & 1 deletion test/spoom/deadcode/plugins/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Module2; end

def test_on_send
plugin = Class.new(Base) do
def on_send(indexer, send)
def on_send(send)
return unless send.name == "dsl_method"
return if send.args.empty?

Expand Down

0 comments on commit 108d6fd

Please sign in to comment.