Skip to content

Commit 2473fe9

Browse files
committed
Mark ActiveJob::Callbacks as alive
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
1 parent 93ec969 commit 2473fe9

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

lib/spoom/deadcode/plugins/active_job.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ module Plugins
77
class ActiveJob < Base
88
ignore_classes_named("ApplicationJob")
99
ignore_methods_named("perform", "build_enumerator", "each_iteration")
10+
11+
CALLBACKS = [
12+
"after_enqueue",
13+
"after_perform",
14+
"around_enqueue",
15+
"around_perform",
16+
"before_enqueue",
17+
"before_perform",
18+
].freeze
19+
20+
# @override
21+
#: (Send send) -> void
22+
def on_send(send)
23+
return unless send.recv.nil? && CALLBACKS.include?(send.name)
24+
25+
send.each_arg(Prism::SymbolNode) do |arg|
26+
@index.reference_method(arg.unescaped, send.location)
27+
end
28+
end
1029
end
1130
end
1231
end

test/spoom/deadcode/plugins/active_job_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ def perform; end
4949
)
5050
end
5151

52+
def test_ignore_active_job_callbacks
53+
@project.write!("app/jobs/foo.rb", <<~RB)
54+
class FooJob
55+
after_enqueue(:ignored1)
56+
after_perform(:ignored2)
57+
around_enqueue(:ignored3)
58+
around_perform(:ignored4)
59+
before_enqueue(:ignored5)
60+
before_perform(:ignored6)
61+
62+
def ignored1; end
63+
def ignored2; end
64+
def ignored3; end
65+
def ignored4; end
66+
def ignored5; end
67+
def ignored6; end
68+
def dead; end
69+
end
70+
RB
71+
72+
index = index_with_plugins
73+
assert_alive(index, "ignored1")
74+
assert_alive(index, "ignored2")
75+
assert_alive(index, "ignored3")
76+
assert_alive(index, "ignored4")
77+
assert_alive(index, "ignored5")
78+
assert_alive(index, "ignored6")
79+
assert_dead(index, "dead")
80+
end
81+
5282
private
5383

5484
#: -> Deadcode::Index

0 commit comments

Comments
 (0)