S1172: Remove this parameter, whose value is ignored in the method

I am experiencing multiple false positives with the rule S1172. While the below example is rather convoluted, there are real motivating use cases.

static class Program
{
    static void Main()
    {
        Console.WriteLine(Method(1));
    }

    private static int Method(int correctValue)
    {
        int value = 0;
        bool Condition()
        {
            return value < correctValue;
        }
        while (ConditionChecker(Condition))
        {
            value++;
        }
        return value;
    }
    private static bool ConditionChecker(Func<bool> condition)
    {
        return condition();
    }
}

The latest version of SonarLint incorrectly states that correctValue is unused.

I am using:

  • C# 8
  • .NET Framework 4.8
  • SonarLint 4.28.0.24595
  • Visual Studio 16.7.7

Hey there.

I believe we’re already tracking this issue at SonarSource/sonar-dotnet #3134.

2 Likes

Thanks for finding that - it looks to be the same issue.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.