Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to identify unused or stale FxCop message suppressions?

We use FxCop's global suppressions to suppress rule violations found in old code. By old code I mean code that was written sometimes years before we turned on code analysis. We fix violations in new code. We cannot fix the violations in the old code all at once so we use suppressions.

Over time our global suppression files have become bloated. Often when a signature has changed on an old method the prior suppression becomes invalid because it no longer matches up with the code. We created new suppressions to ignore the old violation but often the old SuppressMessage attributes were left behind.

Does anybody know how to identify these SupressMessage declarations that do not match up with code? For that matter does anybody know how to identify SuppressMessage attributes that are invalid because there is no violation to supress?

I am thinking there may be a compiler or FxCopCmd warning or log message that might identify unused suppressions. If not that does anybody know of a script or VS extension that does it?

Thanks.

like image 439
Dan Finucane Avatar asked Jan 18 '11 18:01

Dan Finucane


1 Answers

You can use the stand-alone FxCop UI application for this. Add the "Seen Last Run" column to the "Excluded In Source" results tab. After analysis, this column will show a false value for any in-source suppressions for which a corresponding violation was not found during the analysis run. In order to maximize the reliability of the results, you should ensure that you are using the same set of rule assemblies for the analysis that you use when running the analysis from Visual Studio.

BTW, if you would like to be able to break your build when "stale" suppressions are found, you might want to consider voting at https://connect.microsoft.com/visualstudio/feedback/details/277253/add-mechanism-for-detecting-unnecessary-suppressmessageattribute-instances.

like image 106
Nicole Calinoiu Avatar answered Oct 27 '22 00:10

Nicole Calinoiu