From f0d1646a93eac06ef9c3ebd57e285a5263b698a9 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 28 Jul 2023 18:22:59 +0200 Subject: [PATCH 1/2] Fix RCS0060 --- ...terFileScopedNamespaceDeclarationAnalyzer.cs | 3 +++ ...AddEmptyLineAfterFileScopedNamespaceTests.cs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs b/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs index 6d032cc65b..bae7536548 100644 --- a/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs +++ b/src/Formatting.Analyzers/CSharp/BlankLineAfterFileScopedNamespaceDeclarationAnalyzer.cs @@ -40,6 +40,9 @@ private static void AnalyzeFileScopedNamespaceDeclaration(SyntaxNodeAnalysisCont SyntaxNode node = GetNodeAfterNamespaceDeclaration(namespaceDeclaration); + if (node is null) + return; + BlankLineStyle style = context.GetBlankLineAfterFileScopedNamespaceDeclaration(); if (style == BlankLineStyle.None) diff --git a/src/Tests/Formatting.Analyzers.Tests/RCS0060AddEmptyLineAfterFileScopedNamespaceTests.cs b/src/Tests/Formatting.Analyzers.Tests/RCS0060AddEmptyLineAfterFileScopedNamespaceTests.cs index bbc1fa2be2..f63f995fd0 100644 --- a/src/Tests/Formatting.Analyzers.Tests/RCS0060AddEmptyLineAfterFileScopedNamespaceTests.cs +++ b/src/Tests/Formatting.Analyzers.Tests/RCS0060AddEmptyLineAfterFileScopedNamespaceTests.cs @@ -277,4 +277,21 @@ class C } ", options: Options.AddConfigOption(ConfigOptionKeys.BlankLineAfterFileScopedNamespaceDeclaration, false)); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.BlankLineAfterFileScopedNamespaceDeclaration)] + public async Task TestNoDiagnostic_EmptyFileWithComment() + { + await VerifyNoDiagnosticAsync(@" +namespace A.B; + +// x", options: Options.AddConfigOption(ConfigOptionKeys.BlankLineAfterFileScopedNamespaceDeclaration, false)); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.BlankLineAfterFileScopedNamespaceDeclaration)] + public async Task TestNoDiagnostic_EmptyFileWithComment2() + { + await VerifyNoDiagnosticAsync(@" +namespace A.B; +// x", options: Options.AddConfigOption(ConfigOptionKeys.BlankLineAfterFileScopedNamespaceDeclaration, true)); + } } From 0f7e343bc9324c2beb7a9c5958066f1c5ff3bff6 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Fri, 28 Jul 2023 18:24:00 +0200 Subject: [PATCH 2/2] u --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 1d60fb0fe7..cf0c68a786 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [CLI] Fix member full declaration in generated documentation (command `generate-doc`) ([#1130](https://github.com/josefpihrt/roslynator/pull/1130)). - Append `?` to nullable reference types. - Fix [RCS1179](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1179.md) ([#1129](https://github.com/JosefPihrt/Roslynator/pull/1129)). +- Fix [RCS0060](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS0060.md) ([#1139](https://github.com/JosefPihrt/Roslynator/pull/1139)). ## [4.3.0] - 2023-04-24