Fix S2857 FP: Multiple FP on String Interpolation with Verbatim Literal
Opened this issue · 1 comments
Description
When using string interpolation together with verbatim literal we get multiple false positives reported.
Repro steps
string sqlQuery = $@"
SELECT
[Artifact].[Id] AS [{nameof(ArtifactDto.Id)}],
[Artifact].[TagIdentifier] AS [{nameof(ArtifactDto.TagIdentifier)}],
[Artifact].[DomainSpecificId] AS [{nameof(ArtifactDto.DomainSpecificId)}],
[Artifact].[TagReplacements] AS [{nameof(ArtifactDto.TagReplacements)}],
[Artifact].[LocationId] AS [{nameof(ArtifactDto.LocationId)}],
[Location].[Name] AS [{nameof(ArtifactDto.LocationName)}]
FROM
[Artifacts] AS [Artifact]
JOIN
[Locations] AS [Location]
ON
[Artifact].[LocationId] = [Location].[Id]";
Expected behavior
Expected to have no issues raised by analyzer on this piece of code as when using debugger it shows exactly the parsed string contains enough whitespace to be valid SQL.
Actual behavior
12 issues are raised by the analyzer:
Add a space before 'Id' on {nameof(ArtifactDto.Id)}
Add a space before '],' on ArtifactDto.Id)}],
Add a space before 'TagIdentifier' on {nameof(ArtifactDto.TagIdentifier)}
Add a space before '],' on ArtifactDto.TagIdentifier)}],
Add a space before 'DomainSpecificId' on {nameof(ArtifactDto.DomainSpecificId)}
Add a space before '],' on ArtifactDto.DomainSpecificId)}],
Add a space before 'TagReplacements' on {nameof(ArtifactDto.TagReplacements)}
Add a space before '],' on ArtifactDto.TagReplacements)}],
Add a space before 'LocationId' on {nameof(ArtifactDto.LocationId)}
Add a space before '],' on ArtifactDto.LocationId)}],
Add a space before 'LocationName' on {nameof(ArtifactDto.LocationName)}
Add a space before '],' on ArtifactDto.LocationName)}],
Known workarounds
N/A
Related information
- C#/VB.NET Plugins version: C#12
- Visual Studio version: VS2022 (17.9.6)
- MSBuild / dotnet version: MSBuild version 17.9.6+a4ecab324 for .NET / dotnet 8.0.204
- SonarScanner for .NET version (if used): sonar-dotnet analyzer 9.23.1.88495
- Operating System: Windows 10 Pro 22H2
Hello @RicardoLans,
We can confirm this as a False positive. I added your example in #9181 to our code base and put your issue in our backlog.