Skip to content

Commit

Permalink
Remove trailing trivia from IHeaderDictionary in "Use indexer" code f…
Browse files Browse the repository at this point in the history
…ix (#57649)

* Remove trailing trivia from IHeaderDictionary

* Improve test case comment
  • Loading branch information
david-acker committed Sep 5, 2024
1 parent 71f0a94 commit f22b350
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static bool CanReplaceWithIndexer(Diagnostic diagnostic, SyntaxNode root
SyntaxFactory.AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression,
SyntaxFactory.ElementAccessExpression(
memberAccessExpression.Expression,
memberAccessExpression.Expression.WithoutTrailingTrivia(),
SyntaxFactory.BracketedArgumentList(
SyntaxFactory.SeparatedList(new[] { arguments[0] }))),
arguments[1].Expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ await VerifyCS.VerifyCodeFixAsync(
@"
using Microsoft.AspNetCore.Http;
var context = new DefaultHttpContext();
context.Request.Headers[""Accept""] = ""text/html""{|CS1002:|}"
},

// With trailing trivia
{
@"
using Microsoft.AspNetCore.Http;
var context = new DefaultHttpContext();
{|#0:context.Request.Headers
.Add(""Accept"", ""text/html"")|}{|CS1002:|}",
new[]
{
new DiagnosticResult(DiagnosticDescriptors.DoNotUseIHeaderDictionaryAdd)
.WithLocation(0)
.WithMessage(Resources.Analyzer_HeaderDictionaryAdd_Message)
},
@"
using Microsoft.AspNetCore.Http;
var context = new DefaultHttpContext();
context.Request.Headers[""Accept""] = ""text/html""{|CS1002:|}"
}
Expand Down

0 comments on commit f22b350

Please sign in to comment.