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 S2857 FP: Rule is not checking SQL keywords in const interepolated string #6633

Closed
cristian-ambrosini-sonarsource opened this issue Jan 16, 2023 · 2 comments · Fixed by #8966
Assignees
Labels
Area: C# C# rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@cristian-ambrosini-sonarsource
Copy link
Contributor

cristian-ambrosini-sonarsource commented Jan 16, 2023

Description

S2857 fail to check for SQL keywords inside a:

  • constant interpolated string:
  • interpolated string with nameof expression
using System.Data.SqlClient;

public void MyMethod(string unknownValue)
{
  const string One = "One";
  const string myString = $"{One}Two"; // Noncompliant FP
  const string myString1 = $"{nameof(One)}Two"; // Noncompliant FP
  string myString2 = $"{nameof(unknownValue)}Two"; // Noncompliant FP
}
@martin-strecker-sonarsource
Copy link
Contributor

see also #6126

@cristian-ambrosini-sonarsource
Copy link
Contributor Author

cristian-ambrosini-sonarsource commented Sep 28, 2023

As reported by #8102, non-const string are also raising FPs:

    string nonConstOne = "One";
    string empty = string.Empty;

    string s1 = $"{nonConstOne}";              // Compliant
    string s2 = $"{nonConstOne}Two";           // Noncompliant FP
    string s3 = $"{empty}";                    // Compliant
    string s4 = $"{empty}Two";                 // Compliant

    string s5 = $"{{{nonConstOne}}}";          // Noncompliant FP
                                               // Noncompliant@-1 FP

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. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Best Kanban
  
Done
5 participants