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 @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [RCS1146](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1146.md) ([#1098](https://github.com/JosefPihrt/Roslynator/pull/1098)).
- Fix [RCS1154](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1154.md) ([#1105](https://github.com/JosefPihrt/Roslynator/pull/1105)).
- Fix [RCS1211](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1211.md) ([#1095](https://github.com/JosefPihrt/Roslynator/pull/1095)).
- Fix [RCS0005](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS0005.md) ([#1114](https://github.com/JosefPihrt/Roslynator/pull/1114)).

## [4.3.0] - 2023-04-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ private static void AnalyzeEndRegionDirectiveTrivia(SyntaxNodeAnalysisContext co
{
var endRegionDirective = (EndRegionDirectiveTriviaSyntax)context.Node;

if (IsPrecededWithEmptyLineOrRegionDirective())
return;

DiagnosticHelpers.ReportDiagnostic(
context,
DiagnosticRules.AddBlankLineBeforeEndRegionDirective,
Location.Create(endRegionDirective.SyntaxTree, endRegionDirective.Span.WithLength(0)));
if (!IsPrecededWithEmptyLineOrRegionDirective(endRegionDirective))
{
DiagnosticHelpers.ReportDiagnostic(
context,
DiagnosticRules.AddBlankLineBeforeEndRegionDirective,
Location.Create(endRegionDirective.SyntaxTree, endRegionDirective.Span.WithLength(0)));
}

bool IsPrecededWithEmptyLineOrRegionDirective()
static bool IsPrecededWithEmptyLineOrRegionDirective(EndRegionDirectiveTriviaSyntax endRegionDirective)
{
SyntaxTrivia parentTrivia = endRegionDirective.ParentTrivia;

Expand Down Expand Up @@ -78,7 +78,10 @@ bool IsPrecededWithEmptyLineOrRegionDirective()
return false;
}

return en.Current.IsEndOfLineTrivia();
return en.Current.IsKind(
SyntaxKind.EndOfLineTrivia,
SyntaxKind.RegionDirectiveTrivia,
SyntaxKind.EndRegionDirectiveTrivia);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,39 @@ void M()

#endregion
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddBlankLineBeforeEndRegionDirective)]
public async Task TestNoDiagnostic_TwoEndRegions()
{
await VerifyNoDiagnosticAsync(@"
#region
class C
{
#region
void M()
{
}

#endregion

#endregion
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AddBlankLineBeforeEndRegionDirective)]
public async Task TestNoDiagnostic_EmptyRegions()
{
await VerifyNoDiagnosticAsync(@"
#region

#region

#endregion

#endregion
");
}
}