开发者

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

开发者 https://www.devze.com 2023-02-05 03:36 出处:网络
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 co

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消