Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load custom plugins when running spoom deadcode #577

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
1 change: 1 addition & 0 deletions lib/spoom/cli/deadcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def deadcode(*paths)
end

plugin_classes = Spoom::Deadcode.plugins_from_gemfile_lock(context)
plugin_classes.merge(Spoom::Deadcode.load_custom_plugins(context))
if options[:show_plugins]
$stderr.puts "\nLoaded #{blue(plugin_classes.size.to_s)} plugins\n"
plugin_classes.each do |plugin|
Expand Down
40 changes: 40 additions & 0 deletions test/spoom/cli/deadcode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,46 @@ def test_deadcode_show_plugins_default
assert(result.status)
end

def test_deadcode_load_custom_plugins
@project.write!("lib/foo.rb", <<~RB)
def foo; end
def foo_1; end
def foo_2; end
RB

@project.write!(".spoom/deadcode/plugins/foo.rb", <<~RB)
class Foo < Spoom::Deadcode::Plugins::Base
def on_define_method(definition)
index.ignore(definition) if definition.name =~ /^foo_/
end
end
RB

result = @project.spoom("deadcode --show-plugins --no-color")
assert_equal(<<~ERR, result.err)
Collecting files...

Loaded 7 plugins
Spoom::Deadcode::Plugins::Namespaces
Spoom::Deadcode::Plugins::Ruby
Spoom::Deadcode::Plugins::Minitest
Spoom::Deadcode::Plugins::Rake
Spoom::Deadcode::Plugins::Sorbet
Spoom::Deadcode::Plugins::Thor
Foo

Indexing 1 files...
Analyzing 3 definitions against 0 references...

Candidates:
foo lib/foo.rb:1:0-1:12

Found 1 dead candidates
ERR
assert_empty(result.out)
refute(result.status)
end

def test_deadcode_parse_erb
@project.write!("view.erb", <<~ERB)
<%= foo do %>
Expand Down
Loading