diff --git a/ChangeLog.md b/ChangeLog.md index a5a4a3fe3e..3de48a8862 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix analyzer [RCS1261](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1261) ([PR](https://github.com/dotnet/roslynator/pull/1374)) - Fix analyzer [RCS0056](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0056) ([PR](https://github.com/dotnet/roslynator/pull/1373)) - Fix analyzer [RCS1211](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1211) ([PR](https://github.com/dotnet/roslynator/pull/1377)) +- Fix analyzer [RCS0061](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0061) ([PR](https://github.com/dotnet/roslynator/pull/1376)) ## [4.9.0] - 2024-01-10 diff --git a/src/Formatting.Analyzers/CSharp/BlankLineBetweenSwitchSectionsAnalyzer.cs b/src/Formatting.Analyzers/CSharp/BlankLineBetweenSwitchSectionsAnalyzer.cs index dc094c926d..69c10d10ca 100644 --- a/src/Formatting.Analyzers/CSharp/BlankLineBetweenSwitchSectionsAnalyzer.cs +++ b/src/Formatting.Analyzers/CSharp/BlankLineBetweenSwitchSectionsAnalyzer.cs @@ -55,30 +55,30 @@ private static void AnalyzeSwitchStatement(SyntaxNodeAnalysisContext context) { TriviaBlock block = TriviaBlock.FromBetween(previousSection, en.Current); - if (!block.Success) - continue; - - if (block.Kind == TriviaBlockKind.BlankLine) + if (block.Success) { - if (option == BlankLineBetweenSwitchSections.Omit) + if (block.Kind == TriviaBlockKind.BlankLine) + { + if (option == BlankLineBetweenSwitchSections.Omit) + { + ReportDiagnostic(context, block, "Remove"); + } + else if (option == BlankLineBetweenSwitchSections.OmitAfterBlock + && previousLastStatement.IsKind(SyntaxKind.Block)) + { + ReportDiagnostic(context, block, "Remove"); + } + } + else if (option == BlankLineBetweenSwitchSections.Include) { - ReportDiagnostic(context, block, "Remove"); + ReportDiagnostic(context, block, "Add"); } else if (option == BlankLineBetweenSwitchSections.OmitAfterBlock - && previousLastStatement.IsKind(SyntaxKind.Block)) + && !previousLastStatement.IsKind(SyntaxKind.Block)) { - ReportDiagnostic(context, block, "Remove"); + ReportDiagnostic(context, block, "Add"); } } - else if (option == BlankLineBetweenSwitchSections.Include) - { - ReportDiagnostic(context, block, "Add"); - } - else if (option == BlankLineBetweenSwitchSections.OmitAfterBlock - && !previousLastStatement.IsKind(SyntaxKind.Block)) - { - ReportDiagnostic(context, block, "Add"); - } previousSection = en.Current; previousLastStatement = previousSection.Statements.LastOrDefault();