Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.81 KB

File metadata and controls

52 lines (40 loc) · 1.81 KB

SA1011

TypeName SA1011ClosingSquareBracketsMustBeSpacedCorrectly
CheckId SA1011
Category Spacing Rules

Cause

A closing square bracket within a C# statement is not spaced correctly.

Rule description

A violation of this rule occurs when the spacing around a closing square bracket is not correct.

A closing square bracket should never be preceded by whitespace, unless it is the first character on the line.

A closing square bracket should be followed by whitespace unless:

  • It is the last character on the line
  • It is followed by a closing bracket or an opening parenthesis
  • It is followed by a comma or semicolon
  • It is followed by a string interpolation alignment component. For example: $"{x[i]:C}"
  • It is followed by a string interpolation formatting component. For example: $"{x[i],3}"
  • It is followed by certain types of operator symbols
  • It is followed by a nullable reference type annotation for arrays (for example, string[]? items)
  • It is followed by the null-forgiving operator applied to an array or element access (for example, values[0]!)
  • It is immediately followed by a < in an unmanaged calling convention list for a function pointer, for example delegate* unmanaged[Cdecl]<void>

How to fix violations

To fix a violation of this rule, ensure that the spacing around the closing square bracket follows the rule described above.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:ClosingSquareBracketsMustBeSpacedCorrectly", Justification = "Reviewed.")]
#pragma warning disable SA1011 // ClosingSquareBracketsMustBeSpacedCorrectly
#pragma warning restore SA1011 // ClosingSquareBracketsMustBeSpacedCorrectly