From 11a289bbd47edf93285a1338950c0b92aaa3d50e Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Wed, 24 Jul 2024 10:29:26 +0200 Subject: [PATCH 1/2] Add repro for S6678 --- .../TestCases/UsePascalCaseForNamedPlaceHolders.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.cs index e20c77d56f9..9e438eafddc 100644 --- a/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.cs +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.cs @@ -102,4 +102,15 @@ public static class NotILoggerExtensions { public static void LogCritical(NotILogger logger, string message, params object[] args) { } } + + // https://github.com/SonarSource/sonar-dotnet/issues/9545 + public class Repro_9545 + { + public void Method(ILogger logger, int number) + { + logger.LogDebug($"{nameof(Repro_9545)} filter: {{number}}", number); // Compliant - FN + logger.LogDebug("Repro_9545) filter: {number}", number); // Noncompliant + // Secondary @-1 + } + } } From 88f910575aaca308c52f63e41f5a08914d23ddf6 Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Wed, 24 Jul 2024 11:14:05 +0200 Subject: [PATCH 2/2] More test cases --- .../UsePascalCaseForNamedPlaceHoldersTest.cs | 9 +++++++++ .../UsePascalCaseForNamedPlaceHolders.Latest.cs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.Latest.cs diff --git a/analyzers/tests/SonarAnalyzer.Test/Rules/UsePascalCaseForNamedPlaceHoldersTest.cs b/analyzers/tests/SonarAnalyzer.Test/Rules/UsePascalCaseForNamedPlaceHoldersTest.cs index 0362fdb410e..e67301c2f53 100644 --- a/analyzers/tests/SonarAnalyzer.Test/Rules/UsePascalCaseForNamedPlaceHoldersTest.cs +++ b/analyzers/tests/SonarAnalyzer.Test/Rules/UsePascalCaseForNamedPlaceHoldersTest.cs @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +using Microsoft.CodeAnalysis.CSharp; using SonarAnalyzer.Rules.CSharp; using SonarAnalyzer.Rules.MessageTemplates; @@ -39,6 +40,14 @@ public class UsePascalCaseForNamedPlaceHoldersTest public void UsePascalCaseForNamedPlaceHolders_CS() => Builder.AddPaths("UsePascalCaseForNamedPlaceHolders.cs").Verify(); +#if NET + + [TestMethod] + public void UsePascalCaseForNamedPlaceHolders_Latest_CS() => + Builder.AddPaths("UsePascalCaseForNamedPlaceHolders.Latest.cs").WithLanguageVersion(LanguageVersion.Latest).VerifyNoIssues(); + +#endif + [DataTestMethod] [DataRow("LogCritical")] [DataRow("LogDebug")] diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.Latest.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.Latest.cs new file mode 100644 index 00000000000..a34b2791a2c --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/UsePascalCaseForNamedPlaceHolders.Latest.cs @@ -0,0 +1,16 @@ +using System; +using Microsoft.Extensions.Logging; + +// https://github.com/SonarSource/sonar-dotnet/issues/9545 +public class Repro_9545 +{ + public void Method(ILogger logger, int number) + { + logger.LogDebug($@"{nameof(Repro_9545)} filter: {{number}}", number); // Compliant - FN + logger.LogDebug(@$"{nameof(Repro_9545)} filter: {{number}}", number); // Compliant - FN + logger.LogDebug($$"""{{nameof(Repro_9545)}} filter: {number}""", number); // Compliant - FN + logger.LogDebug($$$""" + {{{nameof(Repro_9545)}}} filter: {number} + """, number); // Compliant - FN + } +}