Skip to content

Commit 0ca45c4

Browse files
committed
Merge remote-tracking branch 'DotNetAnalyzers/master' into init-only-setters
2 parents eb49896 + f467479 commit 0ca45c4

30 files changed

+911
-41
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1611CSharp9UnitTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,24 @@ public async Task TestPrimaryRecordConstructorIncludeMissingParametersAsync(stri
3737

3838
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3939
}
40+
41+
[Fact]
42+
[WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
43+
public async Task TestLambdaDiscardParametersAsync()
44+
{
45+
var testCode = @"
46+
/// <summary>Test class.</summary>
47+
public class TestClass
48+
{
49+
/// <summary>Test method.</summary>
50+
public void TestMethod()
51+
{
52+
System.Func<int, int, int> handler = (_, _) => 0;
53+
}
54+
}
55+
";
56+
57+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
58+
}
4059
}
4160
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.DocumentationRules;
10+
using Xunit;
711

812
public partial class SA1612CSharp9UnitTests : SA1612CSharp8UnitTests
913
{
14+
[Fact]
15+
[WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
16+
public async Task TestLambdaDiscardParametersAsync()
17+
{
18+
var testCode = @"
19+
/// <summary>Test class.</summary>
20+
public class TestClass
21+
{
22+
/// <summary>Test method.</summary>
23+
public void TestMethod()
24+
{
25+
System.Func<int, int, int> handler = (_, _) => 0;
26+
}
27+
}
28+
";
29+
30+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
31+
}
1032
}
1133
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1501CSharp9UnitTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,48 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp8.LayoutRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.LayoutRules.SA1501StatementMustNotBeOnASingleLine,
12+
StyleCop.Analyzers.LayoutRules.SA1501CodeFixProvider>;
713

814
public partial class SA1501CSharp9UnitTests : SA1501CSharp8UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
18+
public async Task TestLocalFunctionWithAttributeOnSingleLineAsync()
19+
{
20+
var testCode = @"using System;
21+
22+
class TestClass
23+
{
24+
void Outer()
25+
{
26+
[Obsolete]
27+
void Local(){|#0:{|} int value = 0; }
28+
}
29+
}
30+
";
31+
32+
var fixedCode = @"using System;
33+
34+
class TestClass
35+
{
36+
void Outer()
37+
{
38+
[Obsolete]
39+
void Local()
40+
{
41+
int value = 0;
42+
}
43+
}
44+
}
45+
";
46+
47+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
48+
}
1049
}
1150
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1502CSharp9UnitTests.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
75
{
86
using System.Threading;
@@ -94,6 +92,40 @@ public async Task TestMultiLineRecordWithParameterAsync(string keyword)
9492
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
9593
}
9694

95+
[Fact]
96+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
97+
public async Task TestLocalFunctionWithAttributeOnSingleLineAsync()
98+
{
99+
var testCode = @"using System;
100+
101+
class TestClass
102+
{
103+
void Outer()
104+
{
105+
[Obsolete]
106+
void Local(){|#0:{|} int value = 0; }
107+
}
108+
}
109+
";
110+
111+
var fixedCode = @"using System;
112+
113+
class TestClass
114+
{
115+
void Outer()
116+
{
117+
[Obsolete]
118+
void Local()
119+
{
120+
int value = 0;
121+
}
122+
}
123+
}
124+
";
125+
126+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
127+
}
128+
97129
[Fact]
98130
[WorkItem(3966, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3966")]
99131
public async Task TestPropertiesInitAccessorsAsync()

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1505CSharp9UnitTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
75
{
86
using System.Threading;
@@ -28,5 +26,43 @@ public record TestRecord;
2826

2927
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
3028
}
29+
30+
[Fact]
31+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
32+
public async Task TestLocalFunctionWithAttributeFollowedByBlankLineAsync()
33+
{
34+
var testCode = @"using System;
35+
36+
class TestClass
37+
{
38+
void Outer()
39+
{
40+
[Obsolete]
41+
void Local()
42+
{|#0:{|}
43+
44+
int value = 0;
45+
}
46+
}
47+
}
48+
";
49+
50+
var fixedCode = @"using System;
51+
52+
class TestClass
53+
{
54+
void Outer()
55+
{
56+
[Obsolete]
57+
void Local()
58+
{
59+
int value = 0;
60+
}
61+
}
62+
}
63+
";
64+
65+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
66+
}
3167
}
3268
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1508CSharp9UnitTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
75
{
86
using System.Threading;
@@ -93,5 +91,43 @@ public async Task TestMultiLineRecordWithParameterAsync(string keyword)
9391
FixedCode = testCode,
9492
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
9593
}
94+
95+
[Fact]
96+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
97+
public async Task TestLocalFunctionWithAttributePrecededByBlankLineAsync()
98+
{
99+
var testCode = @"using System;
100+
101+
class TestClass
102+
{
103+
void Outer()
104+
{
105+
[Obsolete]
106+
void Local()
107+
{
108+
int value = 0;
109+
110+
{|#0:}|}
111+
}
112+
}
113+
";
114+
115+
var fixedCode = @"using System;
116+
117+
class TestClass
118+
{
119+
void Outer()
120+
{
121+
[Obsolete]
122+
void Local()
123+
{
124+
int value = 0;
125+
}
126+
}
127+
}
128+
";
129+
130+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
131+
}
96132
}
97133
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1513CSharp9UnitTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
75
{
86
using System.Threading;
@@ -66,6 +64,44 @@ public int X
6664
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
6765
}
6866

67+
[Fact]
68+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
69+
public async Task TestLocalFunctionRequiresBlankLineAsync()
70+
{
71+
var testCode = @"using System;
72+
73+
class TestClass
74+
{
75+
void Outer()
76+
{
77+
[Obsolete]
78+
void Local()
79+
{
80+
}{|#0:
81+
|} int value = 0;
82+
}
83+
}
84+
";
85+
86+
var fixedCode = @"using System;
87+
88+
class TestClass
89+
{
90+
void Outer()
91+
{
92+
[Obsolete]
93+
void Local()
94+
{
95+
}
96+
97+
int value = 0;
98+
}
99+
}
100+
";
101+
102+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
103+
}
104+
69105
[Fact]
70106
[WorkItem(3966, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3966")]
71107
public async Task TestBlankLineAfterInitAccessorAsync()

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/MaintainabilityRules/SA1119CSharp9UnitTests.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.MaintainabilityRules
75
{
86
using System.Threading;
@@ -152,5 +150,38 @@ public object TestMethod(Foo n, int a)
152150
TestCode = testCode,
153151
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
154152
}
153+
154+
[Fact]
155+
[WorkItem(3974, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3974")]
156+
public async Task TestConditionalExpressionWithTargetTypedNewAsync()
157+
{
158+
const string testCode = @"public class TestClass
159+
{
160+
public object GetValue(bool flag)
161+
{
162+
return {|#0:{|#1:(|}flag ? null : new(){|#2:)|}|};
163+
}
164+
}";
165+
166+
const string fixedCode = @"public class TestClass
167+
{
168+
public object GetValue(bool flag)
169+
{
170+
return flag ? null : new();
171+
}
172+
}";
173+
174+
await new CSharpTest()
175+
{
176+
TestCode = testCode,
177+
ExpectedDiagnostics =
178+
{
179+
Diagnostic(DiagnosticId).WithLocation(0),
180+
Diagnostic(ParenthesesDiagnosticId).WithLocation(1),
181+
Diagnostic(ParenthesesDiagnosticId).WithLocation(2),
182+
},
183+
FixedCode = fixedCode,
184+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
185+
}
155186
}
156187
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1312CSharp9UnitTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.NamingRules.SA1312VariableNamesMustBeginWithLowerCaseLetter,
13+
StyleCop.Analyzers.NamingRules.RenameToLowerCaseCodeFixProvider>;
714

815
public partial class SA1312CSharp9UnitTests : SA1312CSharp8UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
19+
public async Task TestLambdaDiscardParametersDoNotReportAsync()
20+
{
21+
var testCode = @"
22+
using System;
23+
24+
public class TestClass
25+
{
26+
public void Test()
27+
{
28+
Func<int, int, int> handler = (_, _) => 0;
29+
}
30+
}
31+
";
32+
33+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
34+
}
1035
}
1136
}

0 commit comments

Comments
 (0)