Skip to content

Commit 775752d

Browse files
committed
Update SA1410 for static anonymous functions
1 parent b9e8f09 commit 775752d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

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

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

814
public partial class SA1410CSharp9UnitTests : SA1410CSharp8UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3973, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3973")]
18+
public async Task TestStaticAnonymousMethodAsync()
19+
{
20+
var testCode = @"using System;
21+
22+
public class TestClass
23+
{
24+
public void TestMethod()
25+
{
26+
Func<int> getValue = static delegate{|#0:()|} { return 3; };
27+
}
28+
}
29+
";
30+
31+
var fixedCode = @"using System;
32+
33+
public class TestClass
34+
{
35+
public void TestMethod()
36+
{
37+
Func<int> getValue = static delegate { return 3; };
38+
}
39+
}
40+
";
41+
42+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
43+
}
1044
}
1145
}

documentation/SA1410.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ A violation of this rule occurs when the parenthesis are present on an anonymous
2727

2828
```csharp
2929
this.Method(delegate() { return 2; });
30+
this.Method(static delegate() { return 2; });
3031
```
3132

3233
The parenthesis are unnecessary and should be removed:
3334

3435
```csharp
3536
this.Method(delegate { return 2; });
37+
this.Method(static delegate { return 2; });
3638
```
3739

3840
## How to fix violations

0 commit comments

Comments
 (0)