suppress SA0102?

May 18, 2010 at 1:50 PM

Can't find the rule in the settings to disable it, presumably because it's an internal rule, so attempting to suppress it using an attribute on the (constructor) method that is failing, but I don't know the namespace or error id that I should be referencing - that's assuming that suppressing would work on internal rules?

The reason I'm doing this is because I'm trying to use an optional parameter as available in c# 4.0, which will be fixed in StyleCop 4.4, but in the meantime, our dev environment has 4.3.3 in the build processes, so this error actually breaks our builds.  The alternative is turn off warnings as errors, but I really don't want to do that because that will lead to a lot of warnings to fix later down the line where people have forgotten to run stylecop on a regular basis before they commited code.

The other alternative is that we don't use optional params until Stylecop 4.4 is out and we've had a chance to update our build processes, but I thought I'd ask and see if suppressing the error was possible.

 

 

May 18, 2010 at 2:17 PM

Can you post a sample to reproduce with?

 

 

May 18, 2010 at 2:54 PM
Edited May 18, 2010 at 2:55 PM
Sure, something like this brief class will show where the syntax error will be generated
(the = sign in the optional parameter), and since StyleCop 4.3.2, I should be able to suppress
certain rules from firing on specified methods, but I don't know what the relevant namespace
and rulename is in order to do this.



using
System.Diagnostics.CodeAnalysis; /// <summary> /// Simple class to highlight the issue /// </summary> public class DocumentCosting { /// <summary> /// Initializes a new instance of the <see cref="MyClass"/> class. /// </summary> /// <param name="aString">some string data</param> /// <param name="anOptionalValue">this is optional</param> [SuppressMessage("StyleCopNameSpace", "SA0102:RuleNameHere")] public MyClass(string aString, bool anOptionalValue = true) { } }

 

May 18, 2010 at 8:00 PM

It is actually not possible to suppress SA0101 or SA0102. These are special case “rules” which are thrown whenever StyleCop encounters an internal error. The only workarounds for you would be to disable this file from analysis completely, or stop using optional parameters until upgrading to StyleCop 4.4.

Thanks.

From: andychurchill [mailto:notifications@codeplex.com]
Sent: Tuesday, May 18, 2010 5:51 AM
To: Jason Allor
Subject: suppress SA0102? [stylecop:213021]

From: andychurchill

Can't find the rule in the settings to disable it, presumably because it's an internal rule, so attempting to suppress it using an attribute on the (constructor) method that is failing, but I don't know the namespace or error id that I should be referencing - that's assuming that suppressing would work on internal rules?

The reason I'm doing this is because I'm trying to use an optional parameter as available in c# 4.0, which will be fixed in StyleCop 4.4, but in the meantime, our dev environment has 4.3.3 in the build processes, so this error actually breaks our builds. The alternative is turn off warnings as errors, but I really don't want to do that because that will lead to a lot of warnings to fix later down the line where people have forgotten to run stylecop on a regular basis before they commited code.

The other alternative is that we don't use optional params until Stylecop 4.4 is out and we've had a chance to update our build processes, but I thought I'd ask and see if suppressing the error was possible.

Read the full discussion online.

To add a post to this discussion, reply to this email (stylecop@discussions.codeplex.com)

To start a new discussion for this project, email stylecop@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com