Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Unused public functions

Is there a way to automatically find all unused public functions in a solution? I have resharper, and right now I have to do a "find usages" on each symbol, which is tedious--it seems like there should be a better way

like image 455
dan Avatar asked May 01 '11 06:05

dan


People also ask

How do you find unused functions in Python?

In Python you can find unused code by using dynamic or static code analyzers. Two examples for dynamic analyzers are coverage and figleaf . They have the drawback that you have to run all possible branches of your code in order to find unused parts, but they also have the advantage that you get very reliable results.

How do you find the dead code?

The quickest way to find dead code is to use a good IDE. Delete unused code and unneeded files. In the case of an unnecessary class, Inline Class or Collapse Hierarchy can be applied if a subclass or superclass is used. To remove unneeded parameters, use Remove Parameter.

How can I see unused methods in eclipse?

UCDetector (Unnecessary Code Detector) is a eclipse PlugIn tool to find unnecessary (dead) public java code. For example public classes, methods or fields which have no references.

Where are unused functions in Visual Studio code?

It is currently not possible to detect unused public methods in VSCode (you can check for updates here). However, if it's a private method, you can mark it as private and VSCode is able to look for whether it is used or not within the scope (although do remember: methods used in the HTML template are public).


1 Answers

Of course there's a better way. Here's what you should do if you use ReSharper 4.5 or later:

  1. Go to ReSharper > Options > Code Inspection > Inspection Severity.
  2. Scroll down to "Unused symbols" category and set all containing items called "Non-private accessibility" to be shown - whether they're shown as hints, warnings, or suggestions is not relevant and is entirely up to you.
  3. In ReSharper > Options > Code Inspection > Settings, check "Analyze errors in whole solution". Press OK to apply changes in ReSharper Options.
  4. Right-click the solution node in Solution Explorer, and select "Find code issues". ReSharper will display various code issues that it detects in your solution in "Inspection results" tool window. Specifically, under "Unused symbols", you'll see all non-private types and members in your code that are not used.
like image 128
Jura Gorohovsky Avatar answered Nov 23 '22 09:11

Jura Gorohovsky