-
Notifications
You must be signed in to change notification settings - Fork 239
Fix S2857 FP: Rule is not checking SQL keywords in const interepolated string #8966
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,32 @@ public void Method() | |
| } | ||
| } | ||
|
|
||
| public class Interpolation | ||
| { | ||
| public const string select = "select"; // Compliant | ||
| public const string truncate = $"{nameof(truncate)}"; // Compliant | ||
| public const string @from = "from"; // Compliant | ||
|
|
||
| public const string s1 = $"{select}"; // Compliant | ||
| public const string s2 = $"{select}Name"; // Noncompliant | ||
| public const string s3 = $"select Name {"from"}"; // Compliant | ||
| public const string s4 = $"select Name {"from"}"; // Compliant | ||
| public const string s5 = $"{select} col1{@from}"; // Noncompliant {{Add a space before 'from'.}} | ||
| // ^^^^^^^ | ||
| public const string s6 = $"{select} col1{{{@from}}}"; | ||
| // ^^ {{Add a space before '}}'.}} | ||
| // ^^^^^^^@-1 {{Add a space before 'from'.}} | ||
| public const string s7 = $"{select} col1{{{@from}}}"; | ||
| // ^^^^^^^ {{Add a space before 'from'.}} | ||
| // ^^@-1 {{Add a space before '}}'.}} | ||
|
|
||
| public const string s8 = truncate + $"col1{@from}"; // here we have an FN on col1 + @from, because of the mixed binary/interpolation scenario | ||
| // ^^^^^^^^^^^^^^ {{Add a space before 'col1{@from}'.}} | ||
|
|
||
| public const string s9 = truncate + $"table"; // Noncompliant | ||
| // ^^^^^^^^ | ||
| } | ||
|
|
||
| // https://github.com/SonarSource/sonar-dotnet/issues/6355 | ||
| public class Repro_6355 | ||
| { | ||
|
|
@@ -82,34 +108,32 @@ void Example(string parameter) | |
| string empty = string.Empty; | ||
|
|
||
| const string s0 = $"{constOne}"; // Compliant | ||
| const string s1 = $"{constOne}Two"; // Noncompliant FP | ||
| const string s2 = $"{nameof(constOne)}Two"; // Noncompliant FP | ||
| const string s1 = $"{constOne}Two"; // Compliant | ||
| const string s2 = $"{nameof(constOne)}Two"; // Compliant | ||
| const string s3 = $"{parameter}"; // Error [CS0133] | ||
| const string s4 = $"{parameter}Two"; // Error [CS0133] | ||
| const string s5 = $"{nameof(parameter)}Two"; // Noncompliant FP | ||
| const string s5 = $"{nameof(parameter)}Two"; // Compliant | ||
| const string s6 = $"{nonConstOne}"; // Error [CS0133] | ||
| const string s7 = $"{nonConstOne}Two"; // Error [CS0133] | ||
| // Noncompliant@-1 FP | ||
| const string s8 = $"{nameof(nonConstOne)}Two"; // Noncompliant FP | ||
| const string s8 = $"{nameof(nonConstOne)}Two"; // Compliant | ||
| const string s9 = $"{empty}"; // Error [CS0133] | ||
| const string s10 = $"{empty}Two"; // Error [CS0133] | ||
| const string s11 = $"{nameof(empty)}Two"; // Noncompliant FP | ||
| const string s11 = $"{nameof(empty)}Two"; // Compliant | ||
|
|
||
| string s12 = $"{constOne}"; // Compliant | ||
| string s13 = $"{constOne}Two"; // Noncompliant FP | ||
| string s14 = $"{nameof(constOne)}Two"; // Noncompliant FP | ||
| string s13 = $"{constOne}Two"; // Compliant | ||
| string s14 = $"{nameof(constOne)}Two"; // Compliant | ||
| string s15 = $"{parameter}"; // Compliant | ||
| string s16 = $"{parameter}Two"; // Compliant | ||
| string s17 = $"{nameof(parameter)}Two"; // Noncompliant FP | ||
| string s17 = $"{nameof(parameter)}Two"; // Compliant | ||
| string s18 = $"{nonConstOne}"; // Compliant | ||
| string s19 = $"{nonConstOne}Two"; // Noncompliant FP | ||
| string s20 = $"{nameof(nonConstOne)}Two"; // Noncompliant FP | ||
| string s19 = $"{nonConstOne}Two"; // Compliant | ||
| string s20 = $"{nameof(nonConstOne)}Two"; // Compliant | ||
| string s21 = $"{empty}"; // Compliant | ||
| string s22 = $"{empty}Two"; // Compliant | ||
| string s23 = $"{nameof(empty)}Two"; // Noncompliant FP | ||
| string s23 = $"{nameof(empty)}Two"; // Compliant | ||
|
|
||
| string s24 = $"{{{nonConstOne}}}"; // Noncompliant FP | ||
| // Noncompliant@-1 FP | ||
| string s24 = $"{{{nonConstOne}}}"; // Compliant | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these do not contain SQL keywords, so now they are correctly compliant. |
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.