StyleCop SA1011 Rule Blocks Nullable Array Declaration
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
- 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#.
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?
I will do it no worries
Should be fixed now