False positive for S1172

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?
    C#

  • Which rule?
    S1172

  • Why do you believe it’s a false-positive/false-negative?
    If a partial method is defined within generated code that is emitted to the “obj” folder, a false positive may occur for rule S1172. When implementing a partial method it may not be necessary to use all parameters, but it is necessary to define them all so that partial method declarations match.

  • Are you using

    • SonarCloud? No
    • SonarQube - which version? No
    • SonarLint - which IDE/version? I’m using SonarAnalyzer.CSharp v9.23.0.88079
      • in connected mode with SonarQube or SonarCloud? No
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

namespace Sonar;

public partial class Test
{
    // S1172 Remove this unused method parameter 'one'. (https://rules.sonarsource.com/csharp/RSPEC-1172)
    private partial string FalsePositive(string one, string two)
    {
        return two;
    }
}
// define in "obj" folder
namespace Sonar;
[System.CodeDom.Compiler.GeneratedCode("example", "1.0")]
public partial class Test
{
    private partial string FalsePositive(string one, string two);

    public void Work()
    {
        FalsePositive("a", "b");
    }
}

Hello dbrink

Thank you for reporting the FP. I can confirm it and added Fix S1172 FP: Don't report on partial method parameters · Issue #8988 · SonarSource/sonar-dotnet · GitHub to our backlog.