Skip to content

Commit 0b2d438

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

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
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

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+
}
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.Test/MaintainabilityRules/SA1402ForBlockDeclarationUnitTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class SA1402ForBlockDeclarationUnitTestsBase : FileMayOnlyContai
2424

2525
protected SA1402SettingsConfiguration SettingsConfiguration { get; set; } = SA1402SettingsConfiguration.ConfigureAsTopLevelType;
2626

27-
protected virtual string SettingKeyword => Keyword;
27+
protected virtual string SettingKeyword => this.Keyword;
2828

2929
protected abstract bool IsConfiguredAsTopLevelTypeByDefault { get; }
3030

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)