Skip to content

Commit

Permalink
Fix analyzer RCS0053 - switch expression (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 14, 2024
1 parent abffb42 commit d42621c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 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/1518))

## [4.12.5] - 2024-09-13

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ static bool AnalyzeToken(SyntaxToken token, bool isOpen)
return true;
}

if (token.IsParentKind(SyntaxKind.SwitchExpression))
return true;

if (token.IsParentKind(SyntaxKind.ObjectInitializerExpression)
&& token.Parent.Parent.IsKind(
SyntaxKind.ObjectCreationExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,25 @@ public string M2(string value, string[] values)
}
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.FixFormattingOfList)]
public async Task TestNoDiagnostic_Multiline_SwitchExpression()
{
await VerifyNoDiagnosticAsync("""
using System;
class C
{
string M(string value) =>
M(value switch
{
"a" => "a",
"b" => "b",
_ => throw new Exception()
});
}
""");
}
}

0 comments on commit d42621c

Please sign in to comment.