Skip to content

Commit bd7b852

Browse files
committed
Support the ref keyword in SA1206
1 parent 4bd51d2 commit bd7b852

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/OrderingRules/SA1206CSharp7UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp7.OrderingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.OrderingRules;
9+
using TestHelper;
10+
using Xunit;
711

812
public class SA1206CSharp7UnitTests : SA1206UnitTests
913
{
14+
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
15+
public async Task TestRefKeywordInStructDeclarationAsync()
16+
{
17+
var testCode = @"private ref struct BitHelper
18+
{
19+
}
20+
";
21+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
22+
}
23+
24+
[Fact(Skip = "The version of the compiler used in these tests does not yet support this feature.")]
25+
public async Task TestRefKeywordInStructDeclarationWrongOrderAsync()
26+
{
27+
var testCode = @"ref private struct BitHelper
28+
{
29+
}
30+
";
31+
32+
DiagnosticResult[] expected = new[]
33+
{
34+
this.CSharpDiagnostic().WithLocation(1, 13).WithArguments("ref", "private"),
35+
};
36+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
37+
}
1038
}
1139
}

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/ModifierOrderHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal enum ModifierType
2929
Static,
3030

3131
/// <summary>
32-
/// Represents other modifiers i.e partial, virtual, abstract, override, extern, unsafe, new, async, const, sealed, readonly, volatile, fixed
32+
/// Represents other modifiers i.e partial, virtual, abstract, override, extern, unsafe, new, async, const, sealed, readonly, volatile, fixed, ref
3333
/// </summary>
3434
Other,
3535
}
@@ -64,6 +64,7 @@ internal static ModifierType GetModifierType(SyntaxToken modifier)
6464
case SyntaxKind.ConstKeyword:
6565
case SyntaxKind.AsyncKeyword:
6666
case SyntaxKind.PartialKeyword:
67+
case SyntaxKind.RefKeyword:
6768
result = ModifierType.Other;
6869
break;
6970
}

0 commit comments

Comments
 (0)