Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix analyzer [RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229) ([PR](https://github.com/dotnet/roslynator/pull/1618))
- Fix analyzer [RCS1174](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1174) ([PR](https://github.com/dotnet/roslynator/pull/1619))
- Fix analyzer [RCS0010](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0010) ([PR](https://github.com/dotnet/roslynator/pull/1620))

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public override void Initialize(AnalysisContext context)
SyntaxKind.InterfaceDeclaration);

context.RegisterSyntaxNodeAction(f => AnalyzeCompilationUnit(f), SyntaxKind.CompilationUnit);
context.RegisterSyntaxNodeAction(f => AnalyzeNamespaceDeclaration(f), SyntaxKind.NamespaceDeclaration);
context.RegisterSyntaxNodeAction(
f => AnalyzeNamespaceDeclaration(f),
#if ROSLYN_4_0
SyntaxKind.FileScopedNamespaceDeclaration,
#endif
SyntaxKind.NamespaceDeclaration);
context.RegisterSyntaxNodeAction(f => AnalyzeEnumDeclaration(f), SyntaxKind.EnumDeclaration);
}

Expand All @@ -61,8 +66,11 @@ private static void AnalyzeCompilationUnit(SyntaxNodeAnalysisContext context)

private static void AnalyzeNamespaceDeclaration(SyntaxNodeAnalysisContext context)
{
#if ROSLYN_4_0
var namespaceDeclaration = (BaseNamespaceDeclarationSyntax)context.Node;
#else
var namespaceDeclaration = (NamespaceDeclarationSyntax)context.Node;

#endif
Analyze(context, namespaceDeclaration.Members);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ enum E
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddBlankLineBetweenDeclarations)]
public async Task Test_FileScopedNamespace()
{
await VerifyDiagnosticAndFixAsync("""
namespace N;

class Foo
{
void M() { }
}[|
|]enum Bar
{
A = 0
}
""", """
namespace N;

class Foo
{
void M() { }
}

enum Bar
{
A = 0
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddBlankLineBetweenDeclarations)]
public async Task TestNoDiagnostic_MemberDeclaration_SingleLine()
{
Expand Down
Loading