Skip to content

Commit e4241f7

Browse files
authored
Fix RCS1197 (#1226)
1 parent 3c68a48 commit e4241f7

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Analyzers/CSharp/Analysis/OptimizeStringBuilderAppendCallAnalysis.cs

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public static void Analyze(SyntaxNodeAnalysisContext context, in SimpleMemberInv
3333

3434
SimpleMemberInvocationExpressionInfo invocationInfo2 = SyntaxInfo.SimpleMemberInvocationExpressionInfo(invocationInfo.Expression);
3535

36+
if (!invocationInfo2.Success)
37+
return;
38+
3639
if (invocationInfo2.NameText != "Append")
3740
return;
3841

src/Tests/Analyzers.Tests/RCS1197OptimizeStringBuilderAppendCallTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,25 @@ void M()
952952
var sb = new StringBuilder().Append($""{Foo}Bar"");
953953
}
954954
}
955+
");
956+
}
957+
958+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.OptimizeStringBuilderAppendCall)]
959+
public async Task TestNoDiagnostic_NoAppendMethodChain()
960+
{
961+
await VerifyNoDiagnosticAsync(@"
962+
using System.Text;
963+
964+
class C
965+
{
966+
string M()
967+
{
968+
var sb = new StringBuilder();
969+
_ = sb.AppendLine();
970+
971+
return sb.ToString();
972+
}
973+
}
955974
");
956975
}
957976
}

src/VisualStudioCode/package/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix [RCS1197](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1197) ([PR](https://github.com/dotnet/roslynator/pull/1226)).
13+
1014
## [4.6.0] - 2023-10-18
1115

1216
### Added

0 commit comments

Comments
 (0)