Skip to content

Commit d42621c

Browse files
authored
Fix analyzer RCS0053 - switch expression (#1518)
1 parent abffb42 commit d42621c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

ChangeLog.md

+4
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/1518))
13+
1014
## [4.12.5] - 2024-09-13
1115

1216
### Fixed

src/Formatting.Analyzers/CSharp/FixFormattingOfListAnalyzer.cs

+3
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ static bool AnalyzeToken(SyntaxToken token, bool isOpen)
428428
return true;
429429
}
430430

431+
if (token.IsParentKind(SyntaxKind.SwitchExpression))
432+
return true;
433+
431434
if (token.IsParentKind(SyntaxKind.ObjectInitializerExpression)
432435
&& token.Parent.Parent.IsKind(
433436
SyntaxKind.ObjectCreationExpression,

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

+19
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,25 @@ public string M2(string value, string[] values)
13591359
}
13601360
}
13611361
1362+
""");
1363+
}
1364+
1365+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
1366+
public async Task TestNoDiagnostic_Multiline_SwitchExpression()
1367+
{
1368+
await VerifyNoDiagnosticAsync("""
1369+
using System;
1370+
1371+
class C
1372+
{
1373+
string M(string value) =>
1374+
M(value switch
1375+
{
1376+
"a" => "a",
1377+
"b" => "b",
1378+
_ => throw new Exception()
1379+
});
1380+
}
13621381
""");
13631382
}
13641383
}

0 commit comments

Comments
 (0)