fix: Improve feature flag code fixer pattern handling - #321
Conversation
Adds support for `featureService.IsEnabled(Flag) is false` and `featureService.IsEnabled(Flag) is true` patterns, which were left unfolded as `if (true is false)` / `if (true is true)` after the invocation was replaced with a literal.
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE Re-reviewed Code Review DetailsNo blocking findings. Optional cleanup, entirely at your discretion: the new |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #321 +/- ##
==========================================
+ Coverage 76.57% 77.30% +0.73%
==========================================
Files 61 61
Lines 1887 2005 +118
Branches 229 259 +30
==========================================
+ Hits 1445 1550 +105
- Misses 360 363 +3
- Partials 82 92 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds tests and implementation for `is not true` / `is not false` patterns. Previously, after the invocation was replaced with `true`, expressions like `true is not false` were left unfolded — the same gap this PR already closed for `is false` / `is true`. The new folding block in SimplifyBooleanExpressions unwraps UnaryPatternSyntax and inverts the match result.
Guard that the Returns() argument is the theory method's own sole parameter, not a nested lambda/local-function parameter and not one of several method parameters. Without this, ConvertTheoryToFact could drop [InlineData] and swap [Theory]→[Fact] while leaving the parameter list intact, producing a [Fact] method with parameters that xUnit1001 rejects. Adds two regression tests: local-function-parameter shape and extra-parameter shape.
🎟️ Tracking
No ticket — internal code fixer improvements.
📔 Objective
Extends the
RemoveFeatureFlagCodeFixerRoslyn code fixer with three improvements:is false/is truepatterns —if (featureService.IsEnabled(Flag) is false)was previously left as unfoldedif (true is false)after the invocation was replaced. Now handled directly in the switch arm (is false→ keep else, drop then) and via a newis-pattern folding step inSimplifyBooleanExpressionsfor non-if contexts.RemoveNode(..., KeepTrailingTrivia)to the existingRemoveNodeCleanlyhelper eliminates extra blank lines left when a multi-line.Returns(...)statement is removed.[Theory]test with exactly[InlineData(true)]+[InlineData(false)]passes its bool param solely into.Returns(param), the fixer now converts it to[Fact], removes the[InlineData]attributes, removes the parameter, and deletes theReturnsline.