Skip to content

Commit d45ce58

Browse files
committed
Also add records as supported member kinds
1 parent a6e0440 commit d45ce58

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,22 @@ private class TestClass10 { }
104104
}
105105

106106
/// <summary>
107-
/// Verifies that the analyzer will properly handle class access levels.
107+
/// Verifies that the analyzer will properly handle type access levels.
108108
/// </summary>
109+
/// <param name="keyword">The keyword used to declare the type.</param>
109110
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
110-
[Fact]
111-
public async Task TestClassOrderingAsync()
111+
[Theory]
112+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
113+
public async Task TestTypeOrderingAsync(string keyword)
112114
{
113-
var testCode = @"internal class TestClass1 { }
114-
public class TestClass2 { }
115+
var testCode = $@"internal {keyword} TestClass1 {{ }}
116+
public {keyword} {{|#0:TestClass2|}} {{ }}
115117
";
116118

117-
var expected = Diagnostic().WithLocation(2, 14).WithArguments("public", "internal");
119+
var expected = Diagnostic().WithLocation(0).WithArguments("public", "internal");
118120

119-
var fixedCode = @"public class TestClass2 { }
120-
internal class TestClass1 { }
121+
var fixedCode = $@"public {keyword} TestClass2 {{ }}
122+
internal {keyword} TestClass1 {{ }}
121123
";
122124

123125
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
@@ -126,12 +128,14 @@ internal class TestClass1 { }
126128
/// <summary>
127129
/// Verifies that the analyzer will properly handle interfaces before classes.
128130
/// </summary>
131+
/// <param name="keyword">The keyword used to declare the type.</param>
129132
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
130-
[Fact]
131-
public async Task TestInternalInterfaceBeforePublicClassAsync()
133+
[Theory]
134+
[MemberData(nameof(CommonMemberData.DataTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
135+
public async Task TestInternalInterfaceBeforePublicClassAsync(string keyword)
132136
{
133-
var testCode = @"internal interface ITestInterface { }
134-
public class TestClass2 { }
137+
var testCode = $@"internal interface ITestInterface {{ }}
138+
public {keyword} TestClass2 {{ }}
135139
";
136140

137141
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1202ElementsMustBeOrderedByAccess.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ internal class SA1202ElementsMustBeOrderedByAccess : DiagnosticAnalyzer
6666
SyntaxKind.IndexerDeclaration,
6767
SyntaxKind.MethodDeclaration,
6868
SyntaxKind.ConversionOperatorDeclaration,
69-
SyntaxKind.OperatorDeclaration);
69+
SyntaxKind.OperatorDeclaration,
70+
SyntaxKindEx.RecordDeclaration,
71+
SyntaxKindEx.RecordStructDeclaration);
7072

7173
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> CompilationUnitAction = HandleCompilationUnit;
7274
private static readonly Action<SyntaxNodeAnalysisContext, StyleCopSettings> BaseNamespaceDeclarationAction = HandleBaseNamespaceDeclaration;

0 commit comments

Comments
 (0)