Skip to content

Commit

Permalink
Load custom plugins when running spoom deadcode
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jul 4, 2024
1 parent 547c005 commit c317deb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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

0 comments on commit c317deb

Please sign in to comment.