Skip to content

Commit dea685c

Browse files
committed
Update SA1015 for function pointers
1 parent f313aaa commit dea685c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1015CSharp9UnitTests.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.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly,
13+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
714

815
public partial class SA1015CSharp9UnitTests : SA1015CSharp8UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3970, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3970")]
19+
public async Task TestFunctionPointerClosingBracketSpacingAsync()
20+
{
21+
var testCode = @"public class TestClass
22+
{
23+
private unsafe delegate*<int, void {|#0:>|}field1;
24+
private unsafe delegate*<int, void {|#1:>|} field2;
25+
}
26+
";
27+
28+
var fixedCode = @"public class TestClass
29+
{
30+
private unsafe delegate*<int, void> field1;
31+
private unsafe delegate*<int, void> field2;
32+
}
33+
";
34+
35+
var expected = new[]
36+
{
37+
Diagnostic(DescriptorNotPreceded).WithLocation(0),
38+
Diagnostic(DescriptorFollowed).WithLocation(0),
39+
Diagnostic(DescriptorNotPreceded).WithLocation(1),
40+
};
41+
42+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
43+
}
1044
}
1145
}

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy
8787
{
8888
case SyntaxKind.TypeArgumentList:
8989
case SyntaxKind.TypeParameterList:
90+
case SyntaxKindEx.FunctionPointerParameterList:
9091
break;
9192

9293
default:

documentation/SA1015.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ nullable symbol, an end of line or a single whitespace (but not whitespace and a
2929
contexts, nullable reference type annotations (for example `List<string?>?`) follow the same rules as nullable value
3030
types.
3131

32+
The `>` token that ends a C# 9 function pointer parameter list follows the same spacing rules, for example `delegate*<int, void>`.
33+
3234
## How to fix violations
3335

3436
To fix a violation of this rule, ensure the whitespace around the closing generic bracket is correct.

0 commit comments

Comments
 (0)