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 RCS1208 #1462

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [CLI] Fix loading of `slnf` files ([PR](https://github.com/dotnet/roslynator/pull/1447))
- [CLI] Fix `--severity-level` ([PR](https://github.com/dotnet/roslynator/pull/1449))
- Fix analyzer [RCS1246](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1246) ([PR](https://github.com/dotnet/roslynator/pull/1451))
- Fix analyzer [RCS1208](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1208) ([PR](https://github.com/dotnet/roslynator/pull/1462))

## [4.12.1] - 2024-04-15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static ReduceIfNestingAnalysisResult Fail(SyntaxNode topNode)
return Success(jumpKind, parent);
}

if (!IsFixable(ifStatement, statements, ref jumpKind))
if (!IsFixable(ifStatement, statements, options, ref jumpKind))
return Fail(node);

switch (parentKind)
Expand Down Expand Up @@ -314,6 +314,7 @@ private static bool IsNestedFix(SyntaxNode node, SemanticModel semanticModel, Re
private static bool IsFixable(
IfStatementSyntax ifStatement,
SyntaxList<StatementSyntax> statements,
ReduceIfNestingOptions options,
ref SyntaxKind jumpKind)
{
int i = statements.Count - 1;
Expand All @@ -326,7 +327,7 @@ private static bool IsNestedFix(SyntaxNode node, SemanticModel semanticModel, Re

if (statements[i] == ifStatement)
{
return true;
return (options & ReduceIfNestingOptions.AllowLastIf) != 0;
}
else if (IsFixableJumpStatement(statements[i], ref jumpKind))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ internal enum ReduceIfNestingOptions
AllowIfInsideIfElse = 1 << 1,
AllowLoop = 1 << 2,
AllowSwitchSection = 1 << 3,
AllowLastIf = 1 << 4,
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public static async Task ComputeRefactoringsAsync(RefactoringContext context, If
options: ReduceIfNestingOptions.AllowNestedFix
| ReduceIfNestingOptions.AllowIfInsideIfElse
| ReduceIfNestingOptions.AllowLoop
| ReduceIfNestingOptions.AllowSwitchSection,
| ReduceIfNestingOptions.AllowSwitchSection
| ReduceIfNestingOptions.AllowLastIf,
cancellationToken: context.CancellationToken);

if (analysis.Success)
Expand Down