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

1

17

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?

Hyperon answered 19/11, 2020 at 15:22 Comment(0)
P
31

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.
Prakash answered 20/11, 2020 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.