Skip to content

Commit

Permalink
Fix analyzer RCS0053 - preprocessor directive (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Oct 5, 2024
1 parent c29e691 commit 1ea4149
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix analyzer [RCS0053](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0053) ([PR](https://github.com/dotnet/roslynator/pull/1547))

## [4.12.7] - 2024-10-01

### Fixed
Expand Down
7 changes: 5 additions & 2 deletions src/Common/CSharp/SyntaxTriviaAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ public static IEnumerable<IndentationInfo> FindIndentations(SyntaxNode node, Tex
{
foreach (SyntaxTrivia trivia in node.DescendantTrivia(span))
{
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia, SyntaxKind.SingleLineDocumentationCommentTrivia))
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia, SyntaxKind.SingleLineDocumentationCommentTrivia)
|| SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
{
int position = trivia.Span.End;
int position = (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
? trivia.FullSpan.End
: trivia.Span.End;

if (span.Contains(position))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,48 @@ void M()
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
public async Task Test_Multiline_PreprocessorDirectives()
{
await VerifyDiagnosticAndFixAsync("""
#define FOO
using System.Collections.Generic;

class C
{
void M()
{
var x = new List<string>([|new string[]
{
"",
"",
#if FOO
"",
#endif
}|]);
}
}
""", """
#define FOO
using System.Collections.Generic;

class C
{
void M()
{
var x = new List<string>(new string[]
{
"",
"",
#if FOO
"",
#endif
});
}
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
public async Task TestNoDiagnostic_Singleline()
{
Expand Down

0 comments on commit 1ea4149

Please sign in to comment.