False positive for S1172

  • What language is this for? C#

  • Which rule? S1172

  • Why do you believe it’s a false-positive/false-negative?
    When used with calling a method using a parameter as dynamic you may find not using some of the parameters.

  • Are you using

    • SonarCloud? no
    • SonarQube - which version? yes
    • SonarLint - which IDE/version? vs2022
      • 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)

public interface I { }

public class A { } : I

public class B { } : I

public class Program {
 public void Main() {
 I data = GetData(); // data can be A or B
 DoSomething((dynamic) data, DateTime.Now);
}

private void DoSomething(A data, DateTime date) {
  Console.WriteLine($"I'm using date parameter: {date}");
}

private void DoSomething(B data, DateTime _) { // S1172 here!
  Console.WriteLine("I'm not using date parameter at all");
}

Hi,

Welcome to the community and thanks for this report!

Can you confirm that you’re using the latest version of SonarLint, i.e. 6.15.0.67199?

 
Thx,
Ann