Skip to content

Commit 8895526

Browse files
Update SA1206 to recognize modifier "file"
#3589
1 parent 2f6d02f commit 8895526

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
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.Test.CSharp11/StyleCop.Analyzers.Test.CSharp11.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.2.0-4.final" />
20+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
2121
<PackageReference Include="xunit" Version="2.4.1" />
2222
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
2323
</ItemGroup>

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

StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal static class SyntaxKindEx
1414
public const SyntaxKind NotKeyword = (SyntaxKind)8440;
1515
public const SyntaxKind ManagedKeyword = (SyntaxKind)8445;
1616
public const SyntaxKind UnmanagedKeyword = (SyntaxKind)8446;
17+
public const SyntaxKind FileKeyword = (SyntaxKind)8449;
1718
public const SyntaxKind NullableKeyword = (SyntaxKind)8486;
1819
public const SyntaxKind EnableKeyword = (SyntaxKind)8487;
1920
public const SyntaxKind WarningsKeyword = (SyntaxKind)8488;

0 commit comments

Comments
 (0)