Skip to content

Commit d3d46e7

Browse files
authored
Merge pull request #3268 from sharwell/empty-record
Allow semicolon for record types without a body
2 parents b17a349 + c52d179 commit d3d46e7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1106CSharp9UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.CSharp;
9+
using Microsoft.CodeAnalysis.Testing;
610
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
11+
using Xunit;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.ReadabilityRules.SA1106CodeMustNotContainEmptyStatements,
14+
StyleCop.Analyzers.ReadabilityRules.SA1106CodeFixProvider>;
715

816
public class SA1106CSharp9UnitTests : SA1106CSharp8UnitTests
917
{
18+
[Fact]
19+
[WorkItem(3267, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3267")]
20+
public async Task TestNoDiagnosticForEmptyRecordDeclarationAsync()
21+
{
22+
var testCode = @"public record Result(int Value);";
23+
24+
await new CSharpTest(LanguageVersion.CSharp9)
25+
{
26+
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
27+
TestCode = testCode,
28+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
29+
}
1030
}
1131
}

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1106CodeMustNotContainEmptyStatements.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ private static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context)
5656
{
5757
var declaration = (BaseTypeDeclarationSyntax)context.Node;
5858

59-
if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken))
59+
if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken)
60+
&& !declaration.OpenBraceToken.IsKind(SyntaxKind.None))
6061
{
6162
context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation()));
6263
}

0 commit comments

Comments
 (0)