C-Sharp icon indicating copy to clipboard operation
C-Sharp copied to clipboard

StyleCop SA1011 Rule Blocks Nullable Array Declaration

Open Kalkwst opened this issue 1 year ago • 2 comments

Describe the bug The StyleCop rule SA1011 ("Closing square brackets must be followed by a space") incorrectly prevents declaring nullable arrays, where the ? operator is used directly after the closing []. The rule currently enforces a space between the closing square bracket ] and the nullable operator ?, which is syntactically incorrect and blocks proper nullable array usage.

To Reproduce

  1. Create a C# file and attempt to declare a nullable array.
int[]? nyNummableArray = null;

Expected behavior StyleCop should allow the ? operator to be placed immediately after the closing square bracket [] in a nullable array declaration, as this is valid syntax in C#.

Actual behavior StyleCop reports an SA1011 violation:

SA1011: Closing square bracket must be followed by a space.

This causes an error, suggesting that there should be a space between ] and ?, which is syntactically invalid in C#.

Kalkwst avatar Oct 09 '24 18:10 Kalkwst

Thanks for reporting, this happens because we should be using beta versions of StyleCop. Only beta versions support modern C# syntax. This bug can be solved by updating used StyleCop version to the latest beta. Do you want to do that or can I mark this issue with 'help wanted' label?

siriak avatar Oct 13 '24 20:10 siriak

I will do it no worries

Kalkwst avatar Oct 14 '24 11:10 Kalkwst

Should be fixed now

siriak avatar Oct 22 '24 17:10 siriak