Skip to content

Commit 0cb2666

Browse files
Update after code review
1 parent dd4688f commit 0cb2666

File tree

2 files changed

+25
-83
lines changed

2 files changed

+25
-83
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/ReadabilityRules/SA1130CSharp12UnitTests.cs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,18 @@ namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
66
using Microsoft.CodeAnalysis.Testing;
77
using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;
88

9-
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
10-
StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax,
11-
StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>;
12-
139
public partial class SA1130CSharp12UnitTests : SA1130CSharp11UnitTests
1410
{
15-
protected override DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
11+
protected override DiagnosticResult[] GetCompilerExpectedResultCodeFixSpecialCases()
1612
{
1713
return new[]
1814
{
19-
Diagnostic().WithLocation(8, 20),
20-
Diagnostic().WithLocation(9, 20),
21-
Diagnostic().WithLocation(10, 25),
22-
Diagnostic().WithLocation(11, 30),
23-
Diagnostic().WithLocation(12, 30),
2415
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
25-
Diagnostic().WithLocation(13, 30),
2616
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
27-
Diagnostic().WithLocation(14, 30),
2817
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
29-
Diagnostic().WithLocation(15, 25),
3018
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
3119
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
3220
};
3321
}
34-
35-
protected override DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
36-
{
37-
return new DiagnosticResult[]
38-
{
39-
Diagnostic().WithLocation(12, 30),
40-
DiagnosticResult.CompilerError("CS1065").WithLocation(12, 53),
41-
Diagnostic().WithLocation(13, 30),
42-
DiagnosticResult.CompilerError("CS7014").WithLocation(13, 47),
43-
Diagnostic().WithLocation(14, 30),
44-
DiagnosticResult.CompilerError("CS1670").WithLocation(14, 47),
45-
Diagnostic().WithLocation(15, 25),
46-
DiagnosticResult.CompilerError("CS1669").WithLocation(15, 42),
47-
DiagnosticResult.CompilerError("CS0225").WithLocation(14, 47),
48-
};
49-
}
50-
51-
protected override DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
52-
{
53-
return new[]
54-
{
55-
Diagnostic().WithSpan(4, 50, 4, 58),
56-
DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50),
57-
};
58-
}
5922
}
6023
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace StyleCop.Analyzers.Test.ReadabilityRules
77
{
88
using System.Diagnostics.CodeAnalysis;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Microsoft.CodeAnalysis;
@@ -190,14 +191,14 @@ internal class TypeName
190191
{
191192
private void Method(object o)
192193
{
193-
Action a = delegate() { Console.WriteLine(); };
194-
Action b = delegate() { Console.WriteLine(); };
195-
Action<int> c = delegate(int x) { Console.WriteLine(); };
196-
Action<int, int> d = delegate(int x, int y) { Console.WriteLine(); };
197-
Action<int, int> e = delegate (int x, int y = 0) { Console.WriteLine(); };
198-
Action<int, int> f = delegate (int x, [Obsolete]int y) { Console.WriteLine(); };
199-
Action<int, int> g = delegate (int x, params int y) { Console.WriteLine(); };
200-
Action<int> h = delegate (int x, __arglist) { Console.WriteLine(); };
194+
Action a = [|delegate|]() { Console.WriteLine(); };
195+
Action b = [|delegate|]() { Console.WriteLine(); };
196+
Action<int> c = [|delegate|](int x) { Console.WriteLine(); };
197+
Action<int, int> d = [|delegate|](int x, int y) { Console.WriteLine(); };
198+
Action<int, int> e = [|delegate|] (int x, int y = 0) { Console.WriteLine(); };
199+
Action<int, int> f = [|delegate|] (int x, [Obsolete]int y) { Console.WriteLine(); };
200+
Action<int, int> g = [|delegate|] (int x, params int y) { Console.WriteLine(); };
201+
Action<int> h = [|delegate|] (int x, __arglist) { Console.WriteLine(); };
201202
}
202203
}";
203204

@@ -219,9 +220,16 @@ private void Method(object o)
219220
}
220221
}";
221222

222-
var expected = this.GetExpectedResultCodeFixSpecialCases();
223+
var expected = this.GetCompilerExpectedResultCodeFixSpecialCases();
223224

224-
var expectedAfterFix = this.GetExpectedResultAfterFixCodeFixSpecialCases();
225+
var expectedAfterFix = this.GetCompilerExpectedResultCodeFixSpecialCases()
226+
.Concat(new[]
227+
{
228+
Diagnostic().WithLocation(12, 30),
229+
Diagnostic().WithLocation(13, 30),
230+
Diagnostic().WithLocation(14, 30),
231+
Diagnostic().WithLocation(15, 25),
232+
});
225233

226234
var test = new CSharpTest
227235
{
@@ -801,11 +809,14 @@ public async Task VerifyInvalidCodeConstructionsAsync()
801809
var testCode = @"using System;
802810
public class TestClass
803811
{
804-
public static EventHandler[] TestMethod() => delegate { };
812+
public static EventHandler[] TestMethod() => [|delegate|] { };
805813
}
806814
";
807815

808-
var expected = this.GetExpectedResultVerifyInvalidCodeConstructions();
816+
var expected = new[]
817+
{
818+
DiagnosticResult.CompilerError("CS1660").WithLocation(4, 50),
819+
};
809820

810821
var test = new CSharpTest
811822
{
@@ -984,47 +995,15 @@ public void Test()
984995
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
985996
}
986997

987-
protected virtual DiagnosticResult[] GetExpectedResultCodeFixSpecialCases()
998+
protected virtual DiagnosticResult[] GetCompilerExpectedResultCodeFixSpecialCases()
988999
{
9891000
return new[]
9901001
{
991-
Diagnostic().WithLocation(8, 20),
992-
Diagnostic().WithLocation(9, 20),
993-
Diagnostic().WithLocation(10, 25),
994-
Diagnostic().WithLocation(11, 30),
995-
Diagnostic().WithLocation(12, 30),
9961002
Diagnostic(CS1065).WithLocation(12, 53),
997-
Diagnostic().WithLocation(13, 30),
9981003
Diagnostic(CS7014).WithLocation(13, 47),
999-
Diagnostic().WithLocation(14, 30),
10001004
Diagnostic(CS1670).WithLocation(14, 47),
1001-
Diagnostic().WithLocation(15, 25),
10021005
Diagnostic(CS1669).WithLocation(15, 42),
10031006
};
10041007
}
1005-
1006-
protected virtual DiagnosticResult[] GetExpectedResultAfterFixCodeFixSpecialCases()
1007-
{
1008-
return new[]
1009-
{
1010-
Diagnostic().WithLocation(12, 30),
1011-
Diagnostic(CS1065).WithLocation(12, 53),
1012-
Diagnostic().WithLocation(13, 30),
1013-
Diagnostic(CS7014).WithLocation(13, 47),
1014-
Diagnostic().WithLocation(14, 30),
1015-
Diagnostic(CS1670).WithLocation(14, 47),
1016-
Diagnostic().WithLocation(15, 25),
1017-
Diagnostic(CS1669).WithLocation(15, 42),
1018-
};
1019-
}
1020-
1021-
protected virtual DiagnosticResult[] GetExpectedResultVerifyInvalidCodeConstructions()
1022-
{
1023-
return new[]
1024-
{
1025-
Diagnostic().WithSpan(4, 50, 4, 58),
1026-
DiagnosticResult.CompilerError("CS1660").WithMessage("Cannot convert anonymous method to type 'EventHandler[]' because it is not a delegate type").WithSpan(4, 50, 4, 62),
1027-
};
1028-
}
10291008
}
10301009
}

0 commit comments

Comments
 (0)