Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S3415 FP/FN: Support named arguments #6630

Closed
cristian-ambrosini-sonarsource opened this issue Jan 13, 2023 · 1 comment · Fixed by #6759
Closed

Fix S3415 FP/FN: Support named arguments #6630

cristian-ambrosini-sonarsource opened this issue Jan 13, 2023 · 1 comment · Fixed by #6759
Assignees
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@cristian-ambrosini-sonarsource
Copy link
Contributor

cristian-ambrosini-sonarsource commented Jan 13, 2023

Description

S3415 doesn't support named arguments and considers only the positions of those, resulting in the following FN/FP:

var str = "";
Assert.AreEqual(actual: "", expected: str); // FN
Assert.AreEqual(expected: "", actual: str); // Compliant
Assert.AreEqual(actual: str, expected: ""); // Noncompliant FP
Assert.AreEqual(expected: str, actual: ""); // Noncompliant

The rule only considers literals but constant values should be checked as well:

var str = "";
Assert.AreEqual(str, "A" + "B");   // FN
Assert.AreEqual(str, ("AB"));      // FN
Assert.AreEqual(str, constString); // FN
Assert.AreEqual(someInt, -1);      // FN
@martin-strecker-sonarsource
Copy link
Contributor

The issue should be solved by using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants