openrewrite / rewrite-feature-flags

OpenRewrite recipes for LaunchDarkly.
Apache License 2.0
2 stars 2 forks source link

Recipe to remove boolVariation and clean up if statement #10

Closed timtebeek closed 10 months ago

timtebeek commented 10 months ago

What's changed?

Add recipe to remove calls like client.boolVariation("flag-key-123abc", context, false) with true or false.

What's your motivation?

Clean up feature flags and code paths.

Have you considered any alternatives or workarounds?

Not really. Quick time boxed (one flight) attempt.

Any additional context

shanman190 commented 10 months ago

@timtebeek, really great start! Just a couple of general ideas:

  1. Just a note in terms of the "Do no harm" principle, this'll walk a fine line which I think is fine. What I mean here is that the end user will have had to be consistent with how they used the flag. If they chose to flip flop between true and false cases within their own code, then this recipe will introduce what would be construed as a bug in behavior -- which should be caught during code review. But if they remained consistent always using the same condition statement, then this recipe will perform it's duties perfectly. Tim pointed out that there is a test case that covers negated usages, so that even if the flag is being used in an inverse way at another call site, that the overall condition is evaluated correctly.

  2. Along the lines of your todo comment in the code related to applying the removal less bluntly, it could be a useful improvement of the RemoveUnusedLocalVariable if it's visitor could be customized with a specific variable(actual OpenRewrite LST element) or a type selector (com.launchdarkly.sdk.*) to remove from a filtering standpoint. This could allow upstream recipe authors to be more specific in terms of what they would like to see removed rather than just everything unused. Default could be to remove everything if the additional options weren't provided.

  3. Should we also potentially consider scheduling a remove unused field visitor to cleanup potential LDClient cases?

timtebeek commented 10 months ago

Thanks for the feedback! I've gone over this one again, and I think we're at a point where we can merge an initial version, even if there's small things we could improve still.

Some future improvements or considerations: