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 + } +} 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 + } + } }