From 8a4c56df473b1041fe0c09013f4e05c15cc9c144 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 19 Oct 2023 09:21:37 +0200 Subject: [PATCH 1/4] Fix RCS1197 --- ...OptimizeStringBuilderAppendCallAnalysis.cs | 3 +++ ...197OptimizeStringBuilderAppendCallTests.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Analyzers/CSharp/Analysis/OptimizeStringBuilderAppendCallAnalysis.cs b/src/Analyzers/CSharp/Analysis/OptimizeStringBuilderAppendCallAnalysis.cs index f0f80e7c04..f235597ff2 100644 --- a/src/Analyzers/CSharp/Analysis/OptimizeStringBuilderAppendCallAnalysis.cs +++ b/src/Analyzers/CSharp/Analysis/OptimizeStringBuilderAppendCallAnalysis.cs @@ -33,6 +33,9 @@ public static void Analyze(SyntaxNodeAnalysisContext context, in SimpleMemberInv SimpleMemberInvocationExpressionInfo invocationInfo2 = SyntaxInfo.SimpleMemberInvocationExpressionInfo(invocationInfo.Expression); + if (!invocationInfo2.Success) + return; + if (invocationInfo2.NameText != "Append") return; diff --git a/src/Tests/Analyzers.Tests/RCS1197OptimizeStringBuilderAppendCallTests.cs b/src/Tests/Analyzers.Tests/RCS1197OptimizeStringBuilderAppendCallTests.cs index 24ab0fdb35..96cee0eff5 100644 --- a/src/Tests/Analyzers.Tests/RCS1197OptimizeStringBuilderAppendCallTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1197OptimizeStringBuilderAppendCallTests.cs @@ -952,6 +952,25 @@ void M() var sb = new StringBuilder().Append($""{Foo}Bar""); } } +"); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeStringBuilderAppendCall)] + public async Task TestNoDiagnostic_NoAppendMethodChain() + { + await VerifyNoDiagnosticAsync(@" +using System.Text; + +class C +{ + string M() + { + var sb = new StringBuilder(); + _ = sb.AppendLine(); + + return sb.ToString(); + } +} "); } } From 2e28688302acf7bc3890fcf607eccbcde3ece09a Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 19 Oct 2023 09:23:21 +0200 Subject: [PATCH 2/4] update --- src/VisualStudioCode/package/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/VisualStudioCode/package/CHANGELOG.md b/src/VisualStudioCode/package/CHANGELOG.md index 885fea7e5a..d303f34b22 100644 --- a/src/VisualStudioCode/package/CHANGELOG.md +++ b/src/VisualStudioCode/package/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([#1226](https://github.com/JosefPihrt/Roslynator/pull/1226)). + ## [4.6.0] - 2023-10-18 ### Added From 468f0d8fe57c5948a9dd062b913c866b2b9a39d7 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 19 Oct 2023 09:30:41 +0200 Subject: [PATCH 3/4] Update src/VisualStudioCode/package/CHANGELOG.md --- src/VisualStudioCode/package/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudioCode/package/CHANGELOG.md b/src/VisualStudioCode/package/CHANGELOG.md index d303f34b22..a6496af67e 100644 --- a/src/VisualStudioCode/package/CHANGELOG.md +++ b/src/VisualStudioCode/package/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([#1226](https://github.com/JosefPihrt/Roslynator/pull/1226)). +- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([#1226](https://github.com/dotnet/roslynator/pull/1226)). ## [4.6.0] - 2023-10-18 From 5b400c83957b41fa39cd37fbeff258f36ea0fb62 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Thu, 19 Oct 2023 09:46:01 +0200 Subject: [PATCH 4/4] Update src/VisualStudioCode/package/CHANGELOG.md --- src/VisualStudioCode/package/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudioCode/package/CHANGELOG.md b/src/VisualStudioCode/package/CHANGELOG.md index a6496af67e..c93c3d722d 100644 --- a/src/VisualStudioCode/package/CHANGELOG.md +++ b/src/VisualStudioCode/package/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([#1226](https://github.com/dotnet/roslynator/pull/1226)). +- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([PR](https://github.com/dotnet/roslynator/pull/1226)). ## [4.6.0] - 2023-10-18