Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow semicolon for record types without a body #3268

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Allow semicolon for record types without a body
Fixes #3267
sharwell committed Dec 7, 2020

Verified

This commit was signed with the committer’s verified signature.
joyeecheung Joyee Cheung
commit c52d179b58f4e7de4ebae04f280d3ede482d2185
Original file line number Diff line number Diff line change
@@ -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
@@ -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()));
}