False positive for S2629 when using concatenated, statically interpolated template messages

  • Language & SDK: C# .NET 8.0.402
  • Operating system: Windows 10
  • Rider 2024.2.5
  • SonarLint plugin version: 10.10.0.79575
  • Is connected mode used: No

This is similar to S2629 false positive for logging string interpolation if the interpolated in are placeholder names.

This example shows that S2629 is giving a false positive:

const string FieldName = "FieldName";
logger.Log(LogLevel.Information, $"{nameof(Benchmarks)} " + //
                                             $"{FieldName}:{{{FieldName}}}", value);

I have created the repo at https://github.com/delixfe/InterpolatedStringLowering.git.

Hey there!

It’s on the list: Fix S2629 FP: Constant interpolated string concatenation · Issue #9653 · SonarSource/sonar-dotnet · GitHub

And next time we release our C# analyzer (and a new version of SonarLint), it should be included

1 Like