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

Add CLI commands for detecting and remove dead code #516

Merged
merged 6 commits into from Mar 6, 2024
Merged

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Mar 1, 2024

Run dead code detection in your project with:

$ spoom deadcode

This will list all the methods and constants that do not appear to be used in your project.

Collecting files...
Indexing 122 files...
Analyzing 1033 definitions against 1128 references...

Candidates:
  Spoom::LSP::ResponseError::data lib/spoom/sorbet/lsp/errors.rb:47:18-47:23
  Spoom::Deadcode::Remover::NodeRemover::delete_line_part lib/spoom/deadcode/remover.rb:300:8-312:11
  Spoom::Deadcode::Indexer::file_name lib/spoom/deadcode/indexer.rb:10:25-10:35
  Spoom::LSP::Notification::method lib/spoom/sorbet/lsp/base.rb:62:18-62:25

  Found 5 dead candidates

You can remove them with Spoom:

$ spoom deadcode remove lib/spoom/sorbet/lsp/errors.rb:47:18-47:23

This will delete the dead code and show you the resulting diff:

@@ -43,9 +43,6 @@
       sig { returns(Integer) }
       attr_reader :code

-      sig { returns(T::Hash[T.untyped, T.untyped]) }
-      attr_reader :data
-
       class << self
         extend T::Sig

@Morriar Morriar added the feature New feature label Mar 1, 2024
@Morriar Morriar self-assigned this Mar 1, 2024
@Morriar Morriar requested a review from a team as a code owner March 1, 2024 17:19
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar merged commit 59d6960 into main Mar 6, 2024
8 checks passed
@Morriar Morriar deleted the at-deadcode-cli branch March 6, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants