Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repro for S6678 #9552

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")]
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to create to support @$ and $$$ syntax available in C# 8 & C# 11.

Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit surprising. It actually should raise given that implementation looks into interpolated string text portions. Nevermind. It is documented now.

logger.LogDebug($$$"""
{{{nameof(Repro_9545)}}} filter: {number}
""", number); // Compliant - FN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
martin-strecker-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
logger.LogDebug("Repro_9545) filter: {number}", number); // Noncompliant
// Secondary @-1
}
}
}
Loading