ReSharper inserts Space after Cast when creating array with collection expression
I was writing this piece of code:var list = (double[])[1, 2, 3, 4];
but after reformatting with ReSharper it inserted a space after the cast:var list = (double[]) [1, 2, 3, 4];
This is a violation against the StyleCop configuration and also against the styles we've set in the editorconfig:
csharp_space_before_open_square_brackets = falsecsharp_space_before_array_access_brackets = falsecsharp_space_after_cast = false
Is this a bug in the ReSharper Formater or have I overlooked an editorconfig setting
Please sign in to leave a comment.
thank you for contacting us.
Please look at the following setting: ReSharper | Options | Code Editing | C# | Formatting Style | Braces Layout | Expressions (initializers, switch expressions, patterns, collections expressions). Try to set it up to "At the end of line (no space)".
Thank you!
I just tried that and it works for this specific case, but it also causes this syntax in a different place:
List<int> a =[1, 2, 3, 4, 5];See there is now no Space between the equals sign and the braces, which is again a violation of the StyleCop configuration.
Why does the Formatter not follow those rules which I've set and clearly define what I want the formatter to do?
csharp_space_before_open_square_brackets = falsecsharp_space_before_array_access_brackets = falsecsharp_space_after_cast = falsethe issue should be fixed in 2024.2 release: https://youtrack.jetbrains.com/issue/RSRP-496869/Reformat-adds-unnecessary-whitespace-on-blank-lines-when-trimtrailingwhitespace-is-false
Please install it and check how it works for you: https://www.jetbrains.com/resharper/download/#section=offline-installer
Thank you!
I'm on the latest Version of ReSharper:
thank you for the answer.
It looks like you were faced with this issue: https://youtrack.jetbrains.com/issue/RSRP-497284/Editorconfig-csharpnewlinebeforeopenbrace-conflicts-with-csharpspaceaftercast
It is not fixed yet.
We are sorry for the inconvenience.