Skip to content

Commit

Permalink
Fix/rcs1208 incorrect recursive behaviour (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesHargreaves12 authored Jul 25, 2023
1 parent 39c7473 commit c6e5678
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [RCS0005](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0005) ([#1114](https://github.com/JosefPihrt/Roslynator/pull/1114)).
- Fix [RCS1176](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1176.md) ([#1122](https://github.com/JosefPihrt/Roslynator/pull/1122)).
- Fix [RCS1085](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1085.md) ([#1120](https://github.com/josefpihrt/roslynator/pull/1120)).
- Fix [RCS1208](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1208.md) ([#1119](https://github.com/JosefPihrt/Roslynator/pull/1119)).

## [4.3.0] - 2023-04-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
context.Document,
ifStatement,
(SyntaxKind)Enum.Parse(typeof(SyntaxKind), diagnostic.Properties["JumpKind"]),
recursive: true,
recursive: false,
cancellationToken: ct);
},
GetEquivalenceKey(diagnostic));
Expand Down
72 changes: 64 additions & 8 deletions src/Tests/Analyzers.Tests/RCS1208ReduceIfNestingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ class C
void M(bool p)
{
var f = () =>
{
[|if|] (p)
{
M2();
}
};
[|if|] (p)
{
M2();
}
};
}
void M2()
Expand All @@ -172,8 +172,7 @@ void M(bool p)
}
M2();
}
;
};
}
void M2()
Expand All @@ -197,7 +196,6 @@ void M3()
{
M2();
}
}
M3();
}
Expand Down Expand Up @@ -558,6 +556,64 @@ void M2()
{
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ReduceIfNesting)]
public async Task TestDiagnostic_DoesNot_IncorrectlyRecurse()
{
await VerifyDiagnosticAndFixAsync(@"
class C
{
void M(bool p, bool q, bool r)
{
[|if|] (r)
{
if (p)
{
var x = 1;
M2();
}
if (q)
{
var x = 2;
M2();
}
}
}
void M2()
{
}
}
", @"
class C
{
void M(bool p, bool q, bool r)
{
if (!r)
{
return;
}
if (p)
{
var x = 1;
M2();
}
if (q)
{
var x = 2;
M2();
}
}
void M2()
{
}
}
");
}
}

0 comments on commit c6e5678

Please sign in to comment.