Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analyzer RCS0053 - switch expression #1518

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
});
}
""");
}
}