views:

75

answers:

1

I want to try to make code reviews go a bit faster. While in VS, on a particular class or .aspx page or whatever it is, I can right-click a variable, method, property and use the Find Usages, that's still a very manual process and I wouldn't want to do this on every single method, property, etc. on a page...because most probably have not been changed.

So is there a quick way to give me a list of faults on a page, references that the developer created and may used at one time, but stopped using it and forgets to clean up?

Not sure of the best way to get some kind of report back that could show me this per page or even per project...

+2  A: 

Resharper can do this

From http://www.jetbrains.com/resharper/features/newfeatures.html

These inspections help you discover:

  • Unused non-private declarations
  • Unused return values of non-private methods
  • Unaccessed non-private fields
  • Unused parameters in non-private members
  • Abstract or virtual events that are never invoked
  • Unassigned fields
  • Members and types that can be made internal instead of public

You can set a hint or warning to error inline.

For each warning u see click on it and then press "Alt+enter". You should get a menu item that says "Inspection options for...". Choose that and set it to error.

You can change multiple severities to error

menu Resharper>Options>Inspection Severity

Some you might want to make errors are

  • Assignment is not used
  • Class is never instantiated
  • Method return value is never used
  • Unaccessed Field
  • Unused decleration
  • Unused type parameter

Turn on sultion wide error reporting

See the little grey dot in the bottom right hand corner of VS. Assuming it is turned off it will be grey. Double click it and then click OK on the dialog.

Simon
FxCop (aka Code Analysis) will also pick up several of these. In fact, some of them are even picked up by the compiler (e.g. unassigned fields) and raised as warnings.
itowlson
+1 for ReSharper - excellent tool, especially with Solution-Wide Analysis on. Also turn on Warnings As Errors in the Visual Studio project options.
TrueWill
Yea, I have resharper but how can I get a listing rather than having to hover over things to see these "discoveries"? I know Resharper gives you great hints but typically in my experience that means you have to look for squigglies and the mouse over them for Resharper suggestions. I'm looking for a much easier way than that. I don't have time to manually look through the entire page if I'm just looking for things "not used" if that's my goal.
CoffeeAddict
for each warning u see u can "Alt+enter" on it. You should get a menu item that says "Inspection options for...". CHoose that and set it to error.
Simon
coffeeaddict see extra info in answer
Simon