Skip to content

Commit e36f105

Browse files
authored
Merge pull request #3591 from bjornhellander/feature/sa1206-file
Update SA1206 to recognize modifier "file"
2 parents afc62f4 + 8895526 commit e36f105

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/OrderingRules/SA1206CSharp11CodeFixProviderUnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp11.OrderingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp10.OrderingRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.OrderingRules.SA1206DeclarationKeywordsMustFollowOrder,
12+
StyleCop.Analyzers.OrderingRules.SA1206CodeFixProvider>;
713

814
public class SA1206CSharp11CodeFixProviderUnitTests : SA1206CSharp10CodeFixProviderUnitTests
915
{
16+
[Fact]
17+
[WorkItem(3589, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3589")]
18+
public async Task VerifyFileKeywordReorderingInClassDeclarationAsync()
19+
{
20+
var testCode = $"static unsafe {{|#0:file|}} class TestClass {{}}";
21+
var fixedTestCode = $"file static unsafe class TestClass {{}}";
22+
23+
var expected = Diagnostic().WithLocation(0).WithArguments("file", "unsafe");
24+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
25+
}
1026
}
1127
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.OrderingRules
77
{
88
using Microsoft.CodeAnalysis;
99
using Microsoft.CodeAnalysis.CSharp;
10+
using StyleCop.Analyzers.Lightup;
1011

1112
internal static class ModifierOrderHelper
1213
{
@@ -21,7 +22,7 @@ internal enum ModifierType
2122
None,
2223

2324
/// <summary>
24-
/// Represents any of access modifiers, i.e <see langword="public"/>, <see langword="protected"/>, <see langword="internal"/>, <see langword="private"/>.
25+
/// Represents any of access modifiers, i.e <see langword="public"/>, <see langword="protected"/>, <see langword="internal"/>, <see langword="private"/>, <see langword="file"/>.
2526
/// </summary>
2627
Access,
2728

@@ -46,6 +47,7 @@ internal static ModifierType GetModifierType(SyntaxToken modifier)
4647
case SyntaxKind.ProtectedKeyword:
4748
case SyntaxKind.InternalKeyword:
4849
case SyntaxKind.PrivateKeyword:
50+
case SyntaxKindEx.FileKeyword:
4951
result = ModifierType.Access;
5052
break;
5153

0 commit comments

Comments
 (0)