Casper Dijkstra
Casper Dijkstra

Reputation: 1885

Find all unused code in my project (Rider/VSCode)

Goal

Ideally, our projects contain no unused namespaces / methods / functions and classes.

It is fairly simple to find the number of usages of all of these, for instance;

enter image description here

Has two usages while the following class is never used:

enter image description here

Such code can remain unnoticed for quite some time, while providing unwanted overhead to the total solution. What I'd like to achieve is an overview of all unused code, so developers can easily assess what should and shouldn't stay in the solution.

Question

Of course we're not going to manually search for these... How can we find all unused code?

Upvotes: 18

Views: 15230

Answers (1)

Jura Gorohovsky
Jura Gorohovsky

Reputation: 10148

To find unused code in Rider:

  1. Select Code | Inspect Code in the application menu.
  2. Choose a scope to inspect (solution, project, or a custom scope).
  3. In the Inspection Results window, group inspections by issue category (and optionally by issue type).
  4. Focus on issues under Redundancies in code and Redundancies in symbol declarations: Inspeciton Results in Rider

Alternatively, as you read or edit your code in the editor, you may encounter specific unused code warnings that Rider shows you. If you want to find all issues similar to one specific issue:

  1. Press Alt+Enter to display Rider's code inspection pop-up.
  2. Press Right arrow to expand options for the current inspection.
  3. Press Right arrow to expand the Find similar issues submenu.
  4. Select a scope to find issues.enter image description here
  5. Work with the Inspection Results window as shown above.

Upvotes: 35

Related Questions