From a720d7fdb33518001cef3a78b07076a0d3f8a330 Mon Sep 17 00:00:00 2001 From: Pavel Mikula <57188685+pavel-mikula-sonarsource@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:46:59 +0200 Subject: [PATCH] S3063: Add FP repro for #7324 (#7331) --- .../TestCases/UnusedStringBuilder.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UnusedStringBuilder.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UnusedStringBuilder.cs index 14c4cd04369..b763dcec213 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UnusedStringBuilder.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UnusedStringBuilder.cs @@ -121,3 +121,40 @@ public static class StringBuilderExtensions { public static string ToStringAndFree(this StringBuilder sb) => string.Empty; } + +// https://github.com/SonarSource/sonar-dotnet/issues/7324 +public class Repro_7324 +{ + public string Concat_Prefix() + { + var sb = new StringBuilder(); // Noncompliant FP + sb.Append("Lorem ipsum"); + var ret = "Prefix: " + sb; + return ret; + } + + public string Concat_Infix() + { + var sb = new StringBuilder(); // Noncompliant FP + sb.Append("Lorem ipsum"); + var ret = "Prefix: " + sb + " suffix"; + return ret; + } + + public string Concat_Suffix() + { + var sb = new StringBuilder(); // Noncompliant FP + sb.Append("Lorem ipsum"); + var ret = sb + " suffix"; + return ret; + } + + public string Concat_OutsideDeclaration() + { + var sb = new StringBuilder(); // Noncompliant FP + sb.Append("Lorem ipsum"); + string ret; + ret = "Prefix: " + sb; + return ret; + } +}