-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2850f21
commit 530c8f4
Showing
16 changed files
with
305 additions
and
20 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
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
109 changes: 109 additions & 0 deletions
109
sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EmptyMethod.CSharp9.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,109 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
void Empty() { } // FN | ||
|
||
void WithComment() | ||
{ | ||
// because | ||
} | ||
|
||
void NotEmpty() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
|
||
record EmptyMethod | ||
{ | ||
void F2() | ||
{ | ||
// Do nothing because of X and Y. | ||
} | ||
|
||
void F3() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
|
||
[Conditional("DEBUG")] | ||
void F4() // Noncompliant {{Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation.}} | ||
{ | ||
} | ||
|
||
protected virtual void F5() | ||
{ | ||
} | ||
|
||
extern void F6(); | ||
|
||
[DllImport("avifil32.dll")] | ||
private static extern void F7(); | ||
} | ||
|
||
abstract record MyR | ||
{ | ||
void F1() { } // Noncompliant | ||
public abstract void F2(); | ||
} | ||
|
||
record MyR2 : MyR | ||
{ | ||
public override void F2() | ||
{ | ||
} | ||
} | ||
|
||
class WithProp | ||
{ | ||
public string Prop | ||
{ | ||
init { } // FN https://github.com/SonarSource/sonar-dotnet/issues/3753 | ||
} | ||
} | ||
|
||
class M | ||
{ | ||
[ModuleInitializer] | ||
internal static void M1() // Noncompliant | ||
{ | ||
} | ||
|
||
[ModuleInitializer] | ||
internal static void M2() | ||
{ | ||
// reason | ||
} | ||
|
||
[ModuleInitializer] | ||
internal static void M3() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
} | ||
|
||
namespace D | ||
{ | ||
partial class C | ||
{ | ||
public partial void Foo(); | ||
public partial void Bar(); | ||
public partial void Qix(); | ||
} | ||
|
||
partial class C | ||
{ | ||
public partial void Foo() { } // Noncompliant | ||
|
||
public partial void Bar() | ||
{ | ||
// comment | ||
} | ||
|
||
public partial void Qix() | ||
{ | ||
Console.WriteLine(); | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EmptyStatement.CSharp9.Fixed.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,18 @@ | ||
using System; | ||
|
||
; // Fixed | ||
; // Fixed | ||
Console.WriteLine(); | ||
while (true) | ||
; // Fixed | ||
|
||
record R | ||
{ | ||
string P | ||
{ | ||
init | ||
{ | ||
|
||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EmptyStatement.CSharp9.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,18 @@ | ||
using System; | ||
|
||
; // Noncompliant {{Remove this empty statement.}} | ||
; // Noncompliant | ||
Console.WriteLine(); | ||
while (true) | ||
; // Noncompliant | ||
|
||
record R | ||
{ | ||
string P | ||
{ | ||
init | ||
{ | ||
; // Noncompliant | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...nalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EnumerableSumInUnchecked.CSharp9.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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
List<int> list = new(); | ||
int d = unchecked(list.Sum()); // Noncompliant {{Refactor this code to handle 'OverflowException'.}} | ||
unchecked | ||
{ | ||
int e = list.Sum(); // Noncompliant | ||
e = Enumerable.Sum(list); // Noncompliant | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EqualityOnModulus.CSharp9.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 System.Collections.Generic; | ||
|
||
nint x = 100; | ||
var y = x % 2 == 1; // Noncompliant; if x is negative, x % 2 == -1 | ||
y = x % 2 != -1; // Noncompliant {{The result of this modulus operation may not be negative.}} | ||
y = 1 == x % 2; // Noncompliant {{The result of this modulus operation may not be positive.}} | ||
|
||
nuint unsignedX = 100; | ||
var xx = unsignedX % 4 == 1; // Noncompliant FP |
24 changes: 24 additions & 0 deletions
24
...zer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/EquatableClassShouldBeSealed.CSharp9.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,24 @@ | ||
using System; | ||
|
||
public record R | ||
{ | ||
public bool Equals(R other) => true; // Error [CS8872] | ||
} | ||
|
||
public sealed record Q | ||
{ | ||
public bool Equals(Q other) => true; // Compliant | ||
} | ||
|
||
public record RecordWithVirtualEquals : IEquatable<RecordWithVirtualEquals> // Compliant | ||
{ | ||
public virtual bool Equals(RecordWithVirtualEquals other) => true; | ||
} | ||
|
||
public abstract record RecordWithAbstractEquals : IEquatable<RecordWithAbstractEquals> // Compliant | ||
{ | ||
public abstract bool Equals(RecordWithAbstractEquals other); | ||
} | ||
|
||
public record R1(string x); // Compliant | ||
public record R2(string x, string y) : R1(x); // Compliant |
Oops, something went wrong.