From c52d179b58f4e7de4ebae04f280d3ede482d2185 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 7 Dec 2020 10:47:36 -0800 Subject: [PATCH] Allow semicolon for record types without a body Fixes #3267 --- .../SA1106CSharp9UnitTests.cs | 20 +++++++++++++++++++ ...SA1106CodeMustNotContainEmptyStatements.cs | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1106CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1106CSharp9UnitTests.cs index 2b01da063..32d3b75f1 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1106CSharp9UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1106CSharp9UnitTests.cs @@ -3,9 +3,29 @@ namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA1106CodeMustNotContainEmptyStatements, + StyleCop.Analyzers.ReadabilityRules.SA1106CodeFixProvider>; public class SA1106CSharp9UnitTests : SA1106CSharp8UnitTests { + [Fact] + [WorkItem(3267, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3267")] + public async Task TestNoDiagnosticForEmptyRecordDeclarationAsync() + { + var testCode = @"public record Result(int Value);"; + + await new CSharpTest(LanguageVersion.CSharp9) + { + ReferenceAssemblies = ReferenceAssemblies.Net.Net50, + TestCode = testCode, + }.RunAsync(CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1106CodeMustNotContainEmptyStatements.cs b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1106CodeMustNotContainEmptyStatements.cs index 5d39cdb4a..4a34e1ac5 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1106CodeMustNotContainEmptyStatements.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1106CodeMustNotContainEmptyStatements.cs @@ -56,7 +56,8 @@ private static void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context) { var declaration = (BaseTypeDeclarationSyntax)context.Node; - if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken)) + if (declaration.SemicolonToken.IsKind(SyntaxKind.SemicolonToken) + && !declaration.OpenBraceToken.IsKind(SyntaxKind.None)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, declaration.SemicolonToken.GetLocation())); }