From b350632b8b88ddb7a6787d010057f0228a58e81d Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 14 Jan 2024 19:48:41 +0100 Subject: [PATCH] Fix RCS1055 (#1361) --- ChangeLog.md | 4 ++++ ...nnecessarySemicolonAtEndOfDeclarationAnalyzer.cs | 13 ++++++++----- ...ssarySemicolonAtEndOfDeclarationAnalyzerTests.cs | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 288aa9a8bf..dc6c547db3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix analyzer [RCS1055](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1055) ([PR](https://github.com/dotnet/roslynator/pull/1361)) + ## [4.9.0] - 2024-01-10 ### Added diff --git a/src/Analyzers/CSharp/Analysis/UnnecessarySemicolonAtEndOfDeclarationAnalyzer.cs b/src/Analyzers/CSharp/Analysis/UnnecessarySemicolonAtEndOfDeclarationAnalyzer.cs index 0467d57bdf..935d49da4d 100644 --- a/src/Analyzers/CSharp/Analysis/UnnecessarySemicolonAtEndOfDeclarationAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/UnnecessarySemicolonAtEndOfDeclarationAnalyzer.cs @@ -121,12 +121,15 @@ private static void AnalyzeEnumDeclaration(SyntaxNodeAnalysisContext context) { var declaration = (EnumDeclarationSyntax)context.Node; - SyntaxToken semicolon = declaration.SemicolonToken; - - if (semicolon.Parent is not null - && !semicolon.IsMissing) + if (declaration.CloseBraceToken.IsKind(SyntaxKind.CloseBraceToken)) { - DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.UnnecessarySemicolonAtEndOfDeclaration, semicolon); + SyntaxToken semicolon = declaration.SemicolonToken; + + if (semicolon.Parent is not null + && !semicolon.IsMissing) + { + DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.UnnecessarySemicolonAtEndOfDeclaration, semicolon); + } } } } diff --git a/src/Tests/Analyzers.Tests/RCS1055UnnecessarySemicolonAtEndOfDeclarationAnalyzerTests.cs b/src/Tests/Analyzers.Tests/RCS1055UnnecessarySemicolonAtEndOfDeclarationAnalyzerTests.cs index 80cb0deb7f..57ec079187 100644 --- a/src/Tests/Analyzers.Tests/RCS1055UnnecessarySemicolonAtEndOfDeclarationAnalyzerTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1055UnnecessarySemicolonAtEndOfDeclarationAnalyzerTests.cs @@ -33,6 +33,14 @@ public async Task TestNoDiagnostic_Interface() { await VerifyNoDiagnosticAsync(@" interface C; +"); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UnnecessarySemicolonAtEndOfDeclaration)] + public async Task TestNoDiagnostic_Enum() + { + await VerifyNoDiagnosticAsync(@" +enum E; "); } }