Skip to content

Commit

Permalink
Add deadcode plugin handling for Object#method
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Sep 30, 2024
1 parent 16bc1a5 commit 2f59938
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/spoom/deadcode/plugins/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def on_send(send)
if last_arg.is_a?(Prism::SymbolNode) || last_arg.is_a?(Prism::StringNode)
@index.reference_method(last_arg.unescaped, send.location)
end
when "method"
arg = send.args.first
@index.reference_method(arg.unescaped, send.location) if arg.is_a?(Prism::SymbolNode)
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/spoom/deadcode/plugins/ruby_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ def test_alive_constants_with_const_source_location
assert_dead(index, "DEAD")
end

def test_alive_methods_with_method
@project.write!("foo.rb", <<~RB)
def alive1; end
def alive2; end
def dead; end
method :alive1
[].map(&method(:alive2))
RB

index = index_with_plugins
assert_alive(index, "alive1")
assert_alive(index, "alive2")
assert_dead(index, "dead")
end

private

sig { returns(Deadcode::Index) }
Expand Down

0 comments on commit 2f59938

Please sign in to comment.