-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
b8607d2
commit d05385a
Showing
4 changed files
with
217 additions
and
0 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
112 changes: 112 additions & 0 deletions
112
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/ParametersCorrectOrder.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,112 @@ | ||
using System; | ||
|
||
namespace Tests.Diagnostics | ||
{ | ||
public interface IInterface | ||
{ | ||
static virtual void SomeMethod(int a, int b) { } // Secondary | ||
} | ||
|
||
public class SomeClass<T> where T : IInterface | ||
{ | ||
public SomeClass() | ||
{ | ||
int a = 1; | ||
int b = 2; | ||
|
||
T.SomeMethod(b, a); // Noncompliant | ||
} | ||
} | ||
} | ||
|
||
// https://github.com/SonarSource/sonar-dotnet/issues/8071 | ||
namespace Repro_8071 | ||
{ | ||
class BaseConstructor | ||
{ | ||
class Base(int a, int b) | ||
{ | ||
Base(int a, int b, string c) : this(b, a) { } // FN: ctor params inverted with additional param after | ||
Base(string c, int a, int b) : this(b, a) { } // FN: ctor params inverted with additional param before | ||
} | ||
|
||
class ParamsFullyInverted(int a, int b) : Base(b, a); // FN | ||
class ParamsPartiallyInverted(int a, int b, int c) : Base(b, a); // FN | ||
class ParamsFullyInvertedWithAdditionalParamAfter(int a, int b, string s) : Base(b, a); // FN | ||
class ParamsFullyInvertedWithAdditionalParamBefore(string s, int a, int b) : Base(b, a); // FN | ||
} | ||
|
||
class WithRecordStructs | ||
{ | ||
void Basics(int a, int b, int c) | ||
{ | ||
_ = new SomeRecord(b, a); // Noncompliant | ||
} | ||
|
||
void WithPromotion(short a, short b) | ||
{ | ||
_ = new SomeRecord(b, a); // Noncompliant | ||
} | ||
|
||
void WithCasting(long a, long b) | ||
{ | ||
_ = new SomeRecord((int)b, (int)a); // FN | ||
} | ||
|
||
record SomeRecord(int a, int b) | ||
{ | ||
public SomeRecord(int a, int b, string c) : this(b, a) { } // FN | ||
public SomeRecord(string c, int a, int b) : this(b, a) { } // FN | ||
} | ||
} | ||
|
||
class WithRecords | ||
{ | ||
void Basics(int a, int b, int c) | ||
{ | ||
_ = new SomeRecordStruct(b, a); // Noncompliant | ||
} | ||
|
||
void WithPromotion(short a, short b) | ||
{ | ||
_ = new SomeRecordStruct(b, a); // Noncompliant | ||
} | ||
|
||
void WithCasting(long a, long b) | ||
{ | ||
_ = new SomeRecordStruct((int)b, (int)a); // FN | ||
} | ||
|
||
record struct SomeRecordStruct(int a, int b) | ||
{ | ||
public SomeRecordStruct(int a, int b, string c) : this(b, a) { } // FN | ||
public SomeRecordStruct(string c, int a, int b) : this(b, a) { } // FN | ||
} | ||
} | ||
} | ||
|
||
namespace Repro_8072 | ||
{ | ||
public class DefaultLambdaParameters | ||
{ | ||
void InvokedFromAnotherLambda() | ||
{ | ||
var f1 = (int a, int b) => a + b; | ||
var paramsFullyInverted = (int a, int b) => f1(b, a); // FN | ||
var paramsFullyInvertedWithAdditionalParamAfter = (int a, int b, string s) => f1(b, a); // FN | ||
var paramsFullyInvertedWithAdditionalParamBefore = (string s, int a, int b) => f1(b, a); // FN | ||
|
||
var f2 = (int a, int b, int c) => a + b + c; | ||
var paramsPartiallyInvertedFirstAndSecond = (int a, int b, int c) => f2(b, a, c); // FN | ||
var paramsPartiallyInvertedFirstAndLast = (int a, int b, int c) => f2(c, b, a); // FN | ||
var paramsPartiallyInvertedSecondAndLast = (int a, int b, int c) => f2(a, c, b); // FN | ||
} | ||
|
||
void InvokedFromLocalFunction() | ||
{ | ||
var f = (int a, int b) => a + b; | ||
|
||
int SomeLocalFunction(int a, int b) => f(b, a); | ||
} | ||
} | ||
} |
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