-
-
Notifications
You must be signed in to change notification settings - Fork 292
Fix RCS1077 formatting when converting Select().ToList() to ConvertAll() #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c501d9
c842642
e6cd046
2830997
99be658
f143154
b80e3d4
7769029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -587,11 +587,26 @@ private static Task<Document> CallConvertAllInsteadOfSelectAsync( | |
| in SimpleMemberInvocationExpressionInfo invocationInfo, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| InvocationExpressionSyntax invocationExpression2 = SimpleMemberInvocationExpressionInfo(invocationInfo.Expression).InvocationExpression; | ||
| InvocationExpressionSyntax toListInvocation = invocationInfo.InvocationExpression; | ||
|
|
||
| InvocationExpressionSyntax newInvocationExpression = ChangeInvokedMethodName(invocationExpression2, "ConvertAll"); | ||
| InvocationExpressionSyntax selectInvocation = SimpleMemberInvocationExpressionInfo(invocationInfo.Expression).InvocationExpression; | ||
|
|
||
| return document.ReplaceNodeAsync(invocationInfo.InvocationExpression, newInvocationExpression, cancellationToken); | ||
| InvocationExpressionSyntax newInvocationExpression = ChangeInvokedMethodName(selectInvocation, "ConvertAll"); | ||
|
|
||
| IEnumerable<SyntaxTrivia> removedTrivia = toListInvocation.DescendantTrivia( | ||
| TextSpan.FromBounds(selectInvocation.Span.End, toListInvocation.Span.End)); | ||
|
|
||
| if (removedTrivia.Any(f => !f.IsWhitespaceOrEndOfLineTrivia())) | ||
| { | ||
| newInvocationExpression = newInvocationExpression.WithTrailingTrivia( | ||
| removedTrivia.Where(f => !f.IsWhitespaceOrEndOfLineTrivia()).Concat(toListInvocation.GetTrailingTrivia())); | ||
| } | ||
| else | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: both branches converge on IEnumerable<SyntaxTrivia> comments = removedTrivia.Where(f => !f.IsWhitespaceOrEndOfLineTrivia());
newInvocationExpression = newInvocationExpression.WithTrailingTrivia(
comments.Concat(toListInvocation.GetTrailingTrivia()));Behavior-equivalent and drops the branch. Also worth materializing |
||
| newInvocationExpression = newInvocationExpression.WithTrailingTrivia(toListInvocation.GetTrailingTrivia()); | ||
| } | ||
|
|
||
| return document.ReplaceNodeAsync(toListInvocation, newInvocationExpression, cancellationToken); | ||
| } | ||
|
|
||
| private static Task<Document> CallSumInsteadOfSelectManyAndCountAsync( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch strips all whitespace/EOL trivia and reattaches surviving comments inline. That's fine for block comments, but a single-line
//comment has no terminating newline of its own — the newline is separateEndOfLineTrivia, which gets stripped here. So this input:would become:
…where the
;is now commented out → compile error. Could we preserve a trailing newline when the salvaged trivia ends in a single-line comment (or otherwise guard against it)? A//-comment variant ofTest_CallConvertAllInsteadOfSelectAndToList_PreservesCommentInRemovedSegmentwould reproduce it.