-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.NET 8 and C# 12: add repros and UTs for rules starting with S in Son…
…arWay (#8126)
- Loading branch information
1 parent
f48c05b
commit 40b2e83
Showing
16 changed files
with
497 additions
and
414 deletions.
There are no files selected for viewing
This file contains 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 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 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
17 changes: 17 additions & 0 deletions
17
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SelfAssignment.CSharp12.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class WithPrimaryConstructorParams(int unused, int usedInInlineInitialization, int usedInMethod) | ||
{ | ||
int usedInInlineInitialization = usedInInlineInitialization; // Compliant: param to field assignment | ||
|
||
WithPrimaryConstructorParams(int usedInMethod) : this(0, 0, usedInMethod) | ||
{ | ||
this.usedInInlineInitialization = usedInInlineInitialization; // Compliant: field to field assignment | ||
usedInMethod = usedInMethod; // Noncompliant: local to local assignment | ||
// Secondary@-1 | ||
} | ||
|
||
void AssigningParamToParam() | ||
{ | ||
usedInMethod = usedInMethod; // Noncompliant: param to param assignment (promoted to unspeakable field behind the scenes) | ||
// Secondary@-1 | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SqlKeywordsDelimitedBySpace.CSharp12.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
|
||
namespace SomeNamespace; // Required since use of default namespace results into FNs | ||
|
||
class PrimaryConstructors | ||
{ | ||
class C1(string sql = "SELECT x" + "FROM y"); // Noncompliant | ||
struct S1(string sql = "SELECT x" + "FROM y"); // Noncompliant | ||
record R1(string sql = "SELECT x" + "FROM y"); // Noncompliant | ||
record struct RS1(string sql = "SELECT x" + "FROM y"); // Noncompliant | ||
} | ||
|
||
class DefaultLambdaParameters | ||
{ | ||
void Test() | ||
{ | ||
var f1 = (string s = "SELECT x" + "FROM y") => s; // Noncompliant | ||
var f2 = (string s1 = "SELECT x", string s2 = "FROM y") => s1 + s2; // Compliant, different strings | ||
} | ||
} | ||
|
||
class CollectionExpressions | ||
{ | ||
void MonoDimensional() | ||
{ | ||
IList<string> a; | ||
a = ["SELECT x" + "FROM y"]; // Noncompliant | ||
a = ["SELECT x" + """FROM y"""]; // Noncompliant | ||
a = ["SELECT x", "FROM y"]; // Compliant, different strings | ||
a = [$"SELECT x{"FROM y"}"]; // Noncompliant | ||
a = [$$$""""SELECT x{{"FROM y"}}""""]; // Compliant | ||
a = [$$""""SELECT x{{"FROM y"}}""""]; // Noncompliant | ||
} | ||
|
||
void MultiDimensional() | ||
{ | ||
IList<IList<string>> a; | ||
a = [ | ||
["SELECT x" + "FROM y", // Noncompliant | ||
"SELECT x"], | ||
["FROM y", | ||
"SELECT x" + "FROM y"] // Noncompliant | ||
]; | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/StringFormatEdgeCasesValidator.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...ts/SonarAnalyzer.UnitTest/TestCases/StringFormatRuntimeExceptionFreeValidator.CSharp11.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.