Skip to content

Commit

Permalink
Fix RCS0023 (#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Jan 8, 2024
1 parent 8ffa81f commit 23b3f7d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix analyzer [RCS0034](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0034) ([PR](https://github.com/dotnet/roslynator/pull/1351))
- Fix analyzer [RCS0023](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0023) ([PR](https://github.com/dotnet/roslynator/pull/1352))

## [4.8.0] - 2024-01-02

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,26 @@ private static void AnalyzeTypeDeclaration(SyntaxNodeAnalysisContext context)

SyntaxToken openBrace = typeDeclaration.OpenBraceToken;

if (openBrace.IsMissing)
if (openBrace.IsKind(SyntaxKind.None)
|| openBrace.IsMissing)
{
return;
}

if (!typeDeclaration.SyntaxTree.IsSingleLineSpan(TextSpan.FromBounds(openBrace.Span.End, openBrace.GetNextToken().SpanStart)))
SyntaxToken closeBrace = typeDeclaration.CloseBraceToken;

if (closeBrace.IsKind(SyntaxKind.None)
|| closeBrace.IsMissing)
{
return;
}

DiagnosticHelpers.ReportDiagnostic(
context,
DiagnosticRules.FormatTypeDeclarationBraces,
openBrace);
if (typeDeclaration.SyntaxTree.IsSingleLineSpan(TextSpan.FromBounds(openBrace.SpanStart, closeBrace.SpanStart)))
{
DiagnosticHelpers.ReportDiagnostic(
context,
DiagnosticRules.FormatTypeDeclarationBraces,
openBrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class C
{
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FormatTypeDeclarationBraces)]
public async Task TestNoDiagnostic_NoBraces()
{
await VerifyNoDiagnosticAsync(@"
class C;
");
}
}

0 comments on commit 23b3f7d

Please sign in to comment.