-
Notifications
You must be signed in to change notification settings - Fork 3
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
Enhancements to remove feature flag recipes #14
Comments
@timtebeek Can I work on this issue? |
Hi @kavitha186 yes thanks for your offer to help! Which element specifically would you like to tackle first? A draft PR with a failing test case is typically a great way to start |
@timtebeek Could you please check my draft PR I have few questions on attempting to tackle "RemoveUnusedLocalVariables does not clean up LDContext when the assignment might have side effects, such as when using the builder. Might need a separate recipe that ignores the potential builder side effect." Should I expect all to be cleared with respect to LDContext? eg: if there is any methods used from LDCotext https://launchdarkly.github.io/java-server-sdk/com/launchdarkly/sdk/LDContext.html . |
@timtebeek Can I take up possibly reuse FindFeatureFlag to identify feature keys in more places Can you please help me to understand where the feature keys are not found currently with findFeature flag? |
Hi @kavitha186 ; appreciate the continued offer to help out! These two PRs already improved what constants we can detect: You'll also see that reflected in a test like this one 6f90bd4. Where we currently fail is a slight alteration where the constant is in another class: @Test
void removeWhenFeatureFlagIsAnExternalConstant() {
rewriteRun(
spec -> spec.recipe(new RemoveBooleanFlag("com.acme.bank.CustomLaunchDarklyWrapper featureFlagEnabled(String, boolean)", "flag-key-123abc", true)),
// language=java
java(
"""
package com.acme.bank;
public class CustomLaunchDarklyWrapper {
public static final String FEATURE_TOGGLE = "flag-key-123abc";
public boolean featureFlagEnabled(String key, boolean fallback) {
return fallback;
}
}
""",
SourceSpec::skip
),
// language=java
java(
"""
import com.acme.bank.CustomLaunchDarklyWrapper;
import static com.acme.bank.CustomLaunchDarklyWrapper.FEATURE_TOGGLE;
class Foo {
private CustomLaunchDarklyWrapper wrapper = new CustomLaunchDarklyWrapper();
void bar() {
if (wrapper.featureFlagEnabled(FEATURE_TOGGLE, false)) {
// Application code to show the feature
System.out.println("Feature is on");
}
else {
// The code to run if the feature is off
System.out.println("Feature is off");
}
}
}
""",
"""
class Foo {
void bar() {
// Application code to show the feature
System.out.println("Feature is on");
}
}
"""
)
);
} I'd expect that to be fairly common, and worth supporting, as folks might very well extract those feature keys to a shared constant. Perhaps this is something we can solve in ConstantFold, but I don't know the full details there to know if that's indeed possible. We did previously use this other method to determine the literal value for a given constant; that might work here once we've determined that the first argument is a constant, not a literal. rewrite-feature-flags/src/main/java/org/openrewrite/featureflags/RemoveBooleanFlag.java Lines 81 to 86 in e481645
So it's a bit up in the air how to approach finding more such feature flags usages, but a welcome addition to phase them out anywhere regardless of how they are used. |
What problem are you trying to solve?
We identified a couple of possible improvements following the first recipe to removed a feature flag.
Describe the solution you'd like
RemoveUnusedLocalVariables
does not clean upLDContext
when the assignment might have side effects, such as when using the builder. Might need a separate recipe that ignores the potential builder side effect.RemoveStringFlag
should remove method calls & conditions when comparing equal Strings #40doAfterVisit
recipes now affect the entireSourceFile
containing a feature flag, but not otherSourceFiles
. we might want to limit that further, although it'd be more effortHave you considered any alternatives or workarounds?
Some of these can be separate recipes in for instance rewrite-static-analysis, that we then reuse here.
The text was updated successfully, but these errors were encountered: