Skip to content

Commit 1ea4149

Browse files
authored
Fix analyzer RCS0053 - preprocessor directive (#1547)
1 parent c29e691 commit 1ea4149

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix analyzer [RCS0053](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0053) ([PR](https://github.com/dotnet/roslynator/pull/1547))
13+
1014
## [4.12.7] - 2024-10-01
1115

1216
### Fixed

src/Common/CSharp/SyntaxTriviaAnalysis.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ public static IEnumerable<IndentationInfo> FindIndentations(SyntaxNode node, Tex
226226
{
227227
foreach (SyntaxTrivia trivia in node.DescendantTrivia(span))
228228
{
229-
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia, SyntaxKind.SingleLineDocumentationCommentTrivia))
229+
if (trivia.IsKind(SyntaxKind.EndOfLineTrivia, SyntaxKind.SingleLineDocumentationCommentTrivia)
230+
|| SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
230231
{
231-
int position = trivia.Span.End;
232+
int position = (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
233+
? trivia.FullSpan.End
234+
: trivia.Span.End;
232235

233236
if (span.Contains(position))
234237
{

src/Tests/Formatting.Analyzers.Tests/RCS0053FixFormattingOfListTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,48 @@ void M()
11111111
""");
11121112
}
11131113

1114+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
1115+
public async Task Test_Multiline_PreprocessorDirectives()
1116+
{
1117+
await VerifyDiagnosticAndFixAsync("""
1118+
#define FOO
1119+
using System.Collections.Generic;
1120+
1121+
class C
1122+
{
1123+
void M()
1124+
{
1125+
var x = new List<string>([|new string[]
1126+
{
1127+
"",
1128+
"",
1129+
#if FOO
1130+
"",
1131+
#endif
1132+
}|]);
1133+
}
1134+
}
1135+
""", """
1136+
#define FOO
1137+
using System.Collections.Generic;
1138+
1139+
class C
1140+
{
1141+
void M()
1142+
{
1143+
var x = new List<string>(new string[]
1144+
{
1145+
"",
1146+
"",
1147+
#if FOO
1148+
"",
1149+
#endif
1150+
});
1151+
}
1152+
}
1153+
""");
1154+
}
1155+
11141156
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
11151157
public async Task TestNoDiagnostic_Singleline()
11161158
{

0 commit comments

Comments
 (0)