Skip to content

fix: Improve feature flag code fixer pattern handling - #321

Draft
justindbaur wants to merge 4 commits into
mainfrom
fix/code-fixer-improvements
Draft

fix: Improve feature flag code fixer pattern handling#321
justindbaur wants to merge 4 commits into
mainfrom
fix/code-fixer-improvements

Conversation

@justindbaur

Copy link
Copy Markdown
Member

🎟️ Tracking

No ticket — internal code fixer improvements.

📔 Objective

Extends the RemoveFeatureFlagCodeFixer Roslyn code fixer with three improvements:

  • is false / is true patternsif (featureService.IsEnabled(Flag) is false) was previously left as unfolded if (true is false) after the invocation was replaced. Now handled directly in the switch arm (is false → keep else, drop then) and via a new is-pattern folding step in SimplifyBooleanExpressions for non-if contexts.
  • Spurious blank lines after mock removal — switching from RemoveNode(..., KeepTrailingTrivia) to the existing RemoveNodeCleanly helper eliminates extra blank lines left when a multi-line .Returns(...) statement is removed.
  • Theory → Fact conversion — when a [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 the Returns line.

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.
@justindbaur justindbaur added the ai-review Request a Claude code review label Aug 12, 2026
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Re-reviewed RemoveFeatureFlagCodeFixer after commit cbaf2cb. The Theory→Fact conversion now ties the Returns(...) argument back to the theory method's own sole parameter (ParameterList.Parameters is [{ } onlyParam] && onlyParam.Identifier.Text == param.Name), which closes both the nested local-function/lambda shape and the extra-parameter shape raised in the previous round; the two new regression tests cover exactly those cases and fall back to the safe "only remove the Returns statement" behavior. The earlier is not true / is not false gap is also closed by the second folding pass in SimplifyBooleanExpressions, and the remaining guards (exactly two single-argument [InlineData] values, semantic IParameterReferenceOperation, single parameter usage) are conservative with negative tests for each. No new findings; Run tests and Build artifacts are green.

Code Review Details

No blocking findings.

Optional cleanup, entirely at your discretion: the new is false switch arm in RemoveIsEnabledCheck now appears redundant with the folding pass added in the same PR (the fallback path produces if (true is false), which folds to if (false) and is then resolved by the literal-if loop with the same trivia handling), and the two is-pattern folding loops in SimplifyBooleanExpressions are near-identical and could be collapsed into one pass.

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.70492% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.30%. Comparing base (a22c13b) to head (cbaf2cb).

Files with missing lines Patch % Lines
....Features.CodeFixers/RemoveFeatureFlagCodeFixer.cs 87.70% 4 Missing and 11 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant