Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/spoom/deadcode/plugins/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ 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 "dup"
@index.reference_method("initialize_dup", send.location)
@index.reference_method("initialize_copy", send.location)
when "clone"
@index.reference_method("initialize_clone", send.location)
@index.reference_method("initialize_copy", send.location)
when "method"
arg = send.args.first
@index.reference_method(arg.unescaped, send.location) if arg.is_a?(Prism::SymbolNode)
Expand Down
30 changes: 30 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,36 @@ def test_alive_constants_with_const_source_location
assert_dead(index, "DEAD")
end

def test_alive_initialize_copy_with_dup
@project.write!("foo.rb", <<~RB)
def initialize_copy(source); end
def initialize_dup(source); end
def dead; end

obj.dup
RB

index = index_with_plugins
assert_alive(index, "initialize_copy")
assert_alive(index, "initialize_dup")
assert_dead(index, "dead")
end

def test_alive_initialize_copy_with_clone
@project.write!("foo.rb", <<~RB)
def initialize_copy(source); end
def initialize_clone(source); end
def dead; end

obj.clone
RB

index = index_with_plugins
assert_alive(index, "initialize_copy")
assert_alive(index, "initialize_clone")
assert_dead(index, "dead")
end

def test_alive_methods_with_method
@project.write!("foo.rb", <<~RB)
def alive1; end
Expand Down
Loading