Skip to content

Commit

Permalink
Merge pull request #3268 from sharwell/empty-record
Browse files Browse the repository at this point in the history
Allow semicolon for record types without a body
  • Loading branch information
sharwell authored Dec 7, 2020
2 parents b17a349 + c52d179 commit d3d46e7
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 d3d46e7

Please sign in to comment.