-
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
RemoveStringFlag
should remove method calls & conditions when comparing equal Strings
#40
Comments
hi @bsgongang ; thanks for the detailed description and offer to help. I think there's (at least) two ways we could go about this. One would be to inline local variables used in the assignment from your call out to the client, before we call out to Another would be to have rewrite-feature-flags/src/main/java/org/openrewrite/featureflags/RemoveStringFlag.java Lines 81 to 86 in f9ffb53
Either approach could work here. A fix to |
RemoveStringFlag
should remove method calls & conditions when comparing equal Strings
I've pushed up a first stage that should help some of these cases to be replaced more easily in openrewrite/rewrite@2882fdc |
Thanks for helping explore this @bsgongang ! I've pushed up a change just now that also inlines locally assigned variables. |
I was using the OpenRewrite rewrite-feature-flags, RemoveStringFlag recipe to remove a feature flag in code.
The recipe replaced the feature flag call with the expected value, but could not use the replaced value to simplify the code.
Here is my code:
code to refactor with above recipe:
After running the recipe the output
code transformation output
Expectation
issue:
if (T1.equals(treatment))
is not being simplified with the treatment value which isT1
; I was expecting further simplification, if (T1.equants(treament == T1)) => if (true)
Describe the solution you'd like
We should enhance the remove feature flag recipe to evaluate expressions with the targeted value, simplify the code, and generate a diff that developers wont have any change to do
Have you considered any alternatives or workarounds?
Trying to add some static analysis recipes or use ast-grep rules to evaluate all expressions with the feature flag assigned value
Additional context
Are you interested in contributing this feature to OpenRewrite? Yes, I am interested
Sure, I would like to work on this. I need a POC from openrewrite with whom i can collaborate to get it done
The text was updated successfully, but these errors were encountered: