Skip to content

Commit f7bf65b

Browse files
committed
Update SA1130 for nullable reference types
1 parent c620514 commit f7bf65b

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/ReadabilityRules/SA1130CSharp8UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp8.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp7.ReadabilityRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax,
12+
StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>;
713

814
public partial class SA1130CSharp8UnitTests : SA1130CSharp7UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3006, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006")]
18+
public async Task TestDelegateInNullableEnabledGenericAsync()
19+
{
20+
var testCode = @"#nullable enable
21+
using System;
22+
23+
public class TestClass
24+
{
25+
public void TestMethod<T>() where T : class
26+
{
27+
Func<T?> resolve = {|#0:delegate|} { return default; };
28+
}
29+
}
30+
";
31+
32+
var fixedCode = @"#nullable enable
33+
using System;
34+
35+
public class TestClass
36+
{
37+
public void TestMethod<T>() where T : class
38+
{
39+
Func<T?> resolve = () => { return default; };
40+
}
41+
}
42+
";
43+
44+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
45+
}
46+
47+
[Fact]
48+
[WorkItem(3006, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006")]
49+
public async Task TestDelegateUsedAsNamedArgumentWithNullableTypesAsync()
50+
{
51+
var testCode = @"#nullable enable
52+
using System;
53+
using System.Linq;
54+
55+
public class TestClass
56+
{
57+
public void Test()
58+
{
59+
Invoke(resolve: {|#0:delegate|}
60+
{
61+
return """";
62+
});
63+
}
64+
65+
private void Invoke(string? description = null, Func<object?, string?> resolve = null!)
66+
{
67+
_ = resolve(0);
68+
}
69+
}
70+
";
71+
72+
var fixedCode = @"#nullable enable
73+
using System;
74+
using System.Linq;
75+
76+
public class TestClass
77+
{
78+
public void Test()
79+
{
80+
Invoke(resolve: arg =>
81+
{
82+
return """";
83+
});
84+
}
85+
86+
private void Invoke(string? description = null, Func<object?, string?> resolve = null!)
87+
{
88+
_ = resolve(0);
89+
}
90+
}
91+
";
92+
93+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
94+
}
1095
}
1196
}

0 commit comments

Comments
 (0)