Attempt to suppress StyleCop SA1513 message: ClosingCurlyBracketMustBeFollowedByBlankLine

I am trying to suppress the following StyleCop message for a specific property:

SA1513: Statements or elements wrapped in curly brackets must be followed by a blank line. 

I am trying to do the following, but it does not work:

  [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] public string CustomerId { get { return this.GetProperty(CustomerIdProperty); } set { if (this.IsNew) { this.SetProperty(CustomerIdProperty, value); } else { throw new ReadOnlyException("Id value can only be changed for a new record."); } } } 

Am I just doing something wrong? Or is it simply impossible? This is a good rule, just invalid in my case for a property.

Update

Tried switching from DocumentationRules to LayoutRules ... still not suppressing.

  [DataObjectField(true, false)] [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] public string CustomerId { get { return this.GetProperty(CustomerIdProperty); } set { if (this.IsNew) { this.SetProperty(CustomerIdProperty, value); } else { throw new ReadOnlyException("Id value can only be changed for a new record."); } } } 
+4
source share
6 answers

I think this might be a problem for StyleCop. What version did you install? This page states that:

Starting with StyleCop 4.3.2, you can suppress a rule violation report by adding suppression attributes to the source code.

I just found that I cannot suppress any messages. The installer that I used just gives version 4.3. The latest version of Codeplex is 4.4.0.0. Make sure this version is installed.

Update

I do some checks and I can suppress DocumentationRules:

  [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")] 

but not SpacingRules or LayoutRules. However, nothing I found indicates why this should be so.

+3
source

Your suppression uses Microsoft.StyleCop.CSharp.DocumentationRules . I think it should be Microsoft.StyleCop.CSharp.LayoutRules .

+3
source

There is a bug in StyleCop that only allows you to suppress certain types of rules. This will be fixed in StyleCop 4.4, which is due to be released shortly.

+2
source

Be careful reading the StyleCop documentation to figure out how to suppress a rule. The following worked in my code:

  [SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Splitting this file into classes would get too confusing.")] 

In the help file:

The SuppressMessage attribute has the following format:

[SuppressMessage ("Rule Category", "Rule Identifier", "Rationale")]

Where:

  • A rule category is the StyleCop rule namespace in which the rule is defined. For example, Microsoft.StyleCop.CSharp.DocumentationRules

  • Rule identifier . The rule identifier using the shortname: longname format.

    For example, SA1600: Elements MustBeDocumented

  • Justification . The text that is used to document the reason for suppressing a message.

And as mentioned, make sure you reference the correct rule namespace.

+1
source
 [SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1513:ClosingCurlyBracketMustBeFollowedByBlankLine", Justification = "There are no issues with this code")] 

Works in the latest version of StyleCop. Just uninstalled Microsoft. Console.

+1
source

Just put an empty line between the get block and your set block.
That’s all you have to do is add one blank line and solve the problem.

-1
source

Source: https://habr.com/ru/post/1306566/


All Articles