Skip to content

Commit

Permalink
Allow semicolon for record types without a body
Browse files Browse the repository at this point in the history
Fixes #3267
  • Loading branch information
sharwell committed Dec 7, 2020
1 parent b17a349 commit c52d179
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down

0 comments on commit c52d179

Please sign in to comment.