-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C#12 reproducers for rules T (#8142)
- Loading branch information
1 parent
40b2e83
commit 0a11018
Showing
11 changed files
with
104 additions
and
2 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
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
14 changes: 14 additions & 0 deletions
14
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestClassShouldHaveTestMethod.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,14 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using NUnit.Framework; | ||
|
||
[TestClass] | ||
class ClassTest1(int primaryConstructor) // Noncompliant | ||
// ^^^^^^^^^^ | ||
{ | ||
} | ||
|
||
[TestFixture] | ||
class ClassTest2(int primaryConstructor) // Noncompliant | ||
// ^^^^^^^^^^ | ||
{ | ||
} |
14 changes: 14 additions & 0 deletions
14
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/ThreadStaticWithInitializer.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,14 @@ | ||
using System; | ||
using Point2D = (int, int); | ||
|
||
public class ThreadStaticWithInitializer | ||
{ | ||
public class Foo | ||
{ | ||
[ThreadStatic] | ||
public static int[] PerThreadArray = [1, 2, 3]; // Noncompliant | ||
|
||
[ThreadStatic] | ||
public static Point2D PerThreadPoint = new Point2D(); // Noncompliant | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TooManyGenericParameters.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,7 @@ | ||
class Bar<T1, T2, T3>(string classParam) // Noncompliant | ||
{ | ||
void Method() | ||
{ | ||
bool GenericLambda<T1, T2, T3, T4>(T1 lambdaParam = default(T1)) => true; // Noncompliant | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TooManyParameters_CustomValues.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,15 @@ | ||
using System; | ||
|
||
public class MyWrongClass(int p1, int p2, int p3, int p4) { } // FN {{Constructor has 4 parameters, which is greater than the 3 authorized.}} | ||
|
||
public class SubClass(int p1, int p2, int p3, int p4) : MyWrongClass(p1, p2, p3, p4) { } // Compliant: base class requires them | ||
|
||
public class SubClass2() : MyWrongClass(1, 2, 3, 4) // Compliant | ||
{ | ||
public SubClass2(int p1, int p2, int p3, int p4, int p5) : this() { } // Noncompliant | ||
|
||
void Method() | ||
{ | ||
var a = (int p1 = 1, int p2 = 2, int p3 = 3, int p4 = 4) => true; // Noncompliant {{Lambda has 4 parameters, which is greater than the 3 authorized.}} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TypeExaminationOnSystemType.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,10 @@ | ||
using System; | ||
using Point2D = (int, int); | ||
|
||
Point2D p = new(1, 2); | ||
|
||
if (p.GetType().IsInstanceOfType(typeof(Point2D))) // Noncompliant | ||
{ /* ... */ } | ||
|
||
typeof(Point2D).IsInstanceOfType("42"); // Compliant | ||
typeof(Point2D).IsInstanceOfType(typeof(Point2D)); // Noncompliant |