This project is read-only.


ReSharper Code Cleanup: SA1001 creates trailing spaces at end of line


When a line of code ends with a comma (e.g. in a multi-line method argument list), the ReSharper Code Cleanup rule "1001: commas must be spaced correctly" adds a single space after the comma, at the end of the line.

According to SA1001 documentation: "A comma should always be followed by a single space, unless it is the last character on the line (...)". The way I read it, this does not strictly state that placing a space after a comma at the end of the line is prohibited (only that it is not required to do so), so the current rule implementation would be correct with respect to the letter of the documentation, but I believe the intention was to recommend not having a trailing space in such scenario,

The implementation would be fixed by adding CSharpTokenType.NEW_LINE to the tokensThatCanBeRightSideOfComma list in the StyleCop.ReSharper???.CodeCleanup.Rules.SpacingRules.CommasMustBeSpacedCorrectly methods.

Another slight issue with that rule implementation is the inclusion of CSharpTokenType.RPARENTH on that list. I don't believe there is a valid construct in C# in which a comma would be followed by a right parenthesis and I could not find such a construct in C# 4.0 grammar (
Closed Dec 1, 2016 at 5:21 AM by csdahlberg
Closing this work item due to its age and because development is moving to GitHub. Please open a new issue at if this still needs to be addressed.


i8beef wrote Oct 1, 2013 at 7:55 PM

Also running into this issue with Code Cleanup and extra spaces being added object initializer parameter lists.

Carnifex wrote Jul 22, 2014 at 11:02 AM

It would be grate if you will fix this issue, because when I add rule to NOT having trailing spaces now after "cleanup code" on perfect good file I get warnings on each multiline parameter method.

Normally formatting document on VS remove this trailing spaces, so there is no point to add them.

Workaround: just disable the rule SA1001 in code cleanup profile. The space after commas will be added if you set proper rule in standard R# setting (Code Edditing -> C# -> Formatting style -> Spaces -> Other -> After comma)