Suppress Message(s)

Sep 20, 2010 at 6:53 PM

I have just installed "Visual Studio 2010 Ultimate"

I was using "StyleCop 4.3" but have also tried "StyleCop 4.4"

I created a new C# project based on "Windows Form Application".

I enabled code analysis on the project "Code Analysis Tab | Selected "Enable Code Analysis on Build (defines CODE_ANALYSIS constant)"

I built the application. Builds with no errors or warnings.

Run Style Cop on the project.

In the "Error List" I select any failing rule and right click. The resulting context menu does not include the "Suppress Message(s)" option that I was expecting. I can manually add the supress message to the source (or GlobalSupression file) by hand (but this an take a long time and is hard get correct). I can not find any style cop rule that presentst the "Supress Message(s)" option in the context menu but several other (I presume FxCop) rules do. 

Sep 22, 2010 at 9:42 PM
Edited Sep 23, 2010 at 7:28 PM

One can enable/disable specific rules in a heirarchal way via global/solution/project (right-click the item in the solution explorer is one way to view/edit this) or can use the mentioned suppression attributes for one-time, well-reasoned exceptions to the rule.  I don't think StyleCop currently has any right-click/context-menu features for the individual warning messages themselves.  However, I do think it would be a pretty useful feature to be able to do things like:

* Context menu item for auto-fix of many rules; especially any of the errors that "format document" or "sort remove usings" automatically fix, might be easy to develop this feature for by triggering those features or whatnot.

* Context menu item to insert a suppression attribute at the appropriate location (just above the method or whatnot), partially filled in with the relevant data pertaining to the warning (but leaving the "reason" for the user to fill in; preferably moving the editor cursor there too).