Skip to content

Commit 0d9f20e

Browse files
Update SA1402 to treat record structs the same way as structs
#3542
1 parent b03c98f commit 0d9f20e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1402CodeFixProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private static async Task<Solution> GetTransformedSolutionAsync(Document documen
9191
case SyntaxKind.EnumDeclaration:
9292
case SyntaxKind.DelegateDeclaration:
9393
case SyntaxKindEx.RecordDeclaration:
94+
case SyntaxKindEx.RecordStructDeclaration:
9495
nodesToRemoveFromExtracted.Add(child);
9596
break;
9697

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
#nullable disable
5+
6+
namespace StyleCop.Analyzers.Test.CSharp10.MaintainabilityRules
7+
{
8+
using StyleCop.Analyzers.Test.MaintainabilityRules;
9+
10+
public class SA1402CSharp10ForRecordStructUnitTests : SA1402ForBlockDeclarationUnitTestsBase
11+
{
12+
public override string Keyword => "record struct";
13+
14+
protected override string SettingKeyword => "struct";
15+
16+
protected override bool IsConfiguredAsTopLevelTypeByDefault => false;
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp11.MaintainabilityRules
5+
{
6+
using StyleCop.Analyzers.Test.CSharp10.MaintainabilityRules;
7+
8+
public class SA1402CSharp11ForRecordStructUnitTests : SA1402CSharp10ForRecordStructUnitTests
9+
{
10+
}
11+
}

StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1402FileMayOnlyContainASingleType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private static bool IsRelevantType(SyntaxNode node, StyleCopSettings settings)
120120
isRelevant = topLevelTypes.Contains(TopLevelType.Interface);
121121
break;
122122
case SyntaxKind.StructDeclaration:
123+
case SyntaxKindEx.RecordStructDeclaration:
123124
isRelevant = topLevelTypes.Contains(TopLevelType.Struct);
124125
break;
125126
case SyntaxKind.EnumDeclaration:

0 commit comments

Comments
 (0)