C# 7.0 discards "_" should not trigger S1854, S1172

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Error	S1854	Remove this useless assignment to local variable '_'.

and

Severity	Code	Description	Project	File	Line	Suppression State
Error	S1172	Remove this parameter '_', whose value is ignored in the method.

See https://docs.microsoft.com/en-us/dotnet/csharp/discards

1 Like

Hi Oisin,

Can you share some code samples to see exact situation for each rule?

What version of analyzer do you use?

_ = Method(); // explicitly ignore return value

and

public void override MyMethod(string foo, object _) {  ... } // explicitly ignore 2nd parameter

sonarlint extension vs 2019 - 4.20.0.16339

Hi Oisin,

I’m unfortunately unable to reproduce the issues with (latest) SonarLint 4.20.

Assign to discard pattern does not trigger S1854 in C# 7 project.
Rule S1172 is not triggered for override members, just because you can’t remove the parameter. Besides that, using _ here is not a discard pattern. It’s variable declaration and you can use variable _ in the code.

Can you provide some small demo project to test it?