-
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.
- Loading branch information
1 parent
7288bf9
commit 1f2290e
Showing
4 changed files
with
141 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
39 changes: 39 additions & 0 deletions
39
...s/tests/SonarAnalyzer.UnitTest/TestCases/RedundantDeclaration.CSharp12.ArraySize.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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AliasAnyType | ||
{ | ||
using Int = int; | ||
using IntArray = int[]; | ||
using IntNullable = int?; | ||
using Point = (int x, int y); | ||
using ThreeInts = int[3]; // Error [CS0270]: Array size cannot be specified in a variable declaration | ||
using IntToIntFunc = Func<int, int>; | ||
|
||
class AClass | ||
{ | ||
void AliasWithArraySize() | ||
{ | ||
IntArray a1 = new Int[] { 1, 2, 3 }; // Fixed | ||
} | ||
|
||
void AliasWithUnnecessaryType() | ||
{ | ||
IntToIntFunc f = (Int i) => i; // Fixed | ||
} | ||
|
||
void AliasWithInitializer() | ||
{ | ||
IntArray a1 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
|
||
void AliasWithEmptyParamsList() | ||
{ | ||
IntArray a1 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...narAnalyzer.UnitTest/TestCases/RedundantDeclaration.CSharp12.LambdaParameterType.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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AliasAnyType | ||
{ | ||
using Int = int; | ||
using IntArray = int[]; | ||
using IntNullable = int?; | ||
using Point = (int x, int y); | ||
using ThreeInts = int[3]; // Error [CS0270]: Array size cannot be specified in a variable declaration | ||
using IntToIntFunc = Func<int, int>; | ||
|
||
class AClass | ||
{ | ||
void AliasWithArraySize() | ||
{ | ||
IntArray a1 = new Int[3] { 1, 2, 3 }; // Fixed | ||
} | ||
|
||
void AliasWithUnnecessaryType() | ||
{ | ||
IntToIntFunc f = (i) => i; // Fixed | ||
} | ||
|
||
void AliasWithInitializer() | ||
{ | ||
IntArray a1 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
|
||
void AliasWithEmptyParamsList() | ||
{ | ||
IntArray a1 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/RedundantDeclaration.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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AliasAnyType | ||
{ | ||
using Int = int; | ||
using IntArray = int[]; | ||
using IntNullable = int?; | ||
using Point = (int x, int y); | ||
using ThreeInts = int[3]; // Error [CS0270]: Array size cannot be specified in a variable declaration | ||
using IntToIntFunc = Func<int, int>; | ||
|
||
class AClass | ||
{ | ||
void AliasWithArraySize() | ||
{ | ||
IntArray a1 = new Int[3] { 1, 2, 3 }; // Noncompliant | ||
} | ||
|
||
void AliasWithUnnecessaryType() | ||
{ | ||
IntToIntFunc f = (Int i) => i; // Noncompliant {{Remove the type specification; it is redundant.}} | ||
} | ||
|
||
void AliasWithInitializer() | ||
{ | ||
IntArray a1 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray { }; // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
|
||
void AliasWithEmptyParamsList() | ||
{ | ||
IntArray a1 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
var a2 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
int[] a3 = new IntArray(); // Error [CS8386]: Invalid object creation | ||
} | ||
} | ||
} |