-
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
Remove unused local variables despite potential side effects after removing feature flag #35
Remove unused local variables despite potential side effects after removing feature flag #35
Conversation
8b1b29b
to
57a6ecf
Compare
@timtebeek I had 2 test cases and one of them where LDContext had assigned builder methods - Expectation is the builder methods also has to be cleaned up. An another test cases where I tried to use Create method on LDContext and builderWithContext, I'm expecting it to clear everything , but both the actual and expected result is so unexpected . Can you please what is expected in the testcase "removeUnusedLDContextWithBuilderContext". thanks . |
hi @kavitha186 ! Great to see these test cases added; I think indeed you're right in expecting these LDContext objects to be cleared out where possible. Rather than a separate recipe it might make most sense to add a new nullable argument to RemoveUnusedLocalVariables for something like: rewrite-feature-flags/src/main/java/org/openrewrite/featureflags/RemoveBooleanFlag.java Line 73 in 2c9a406
Would you be willing to push up that matching change as well? Much appreciated that you're chiming in here for the improvements. :) |
I've pushed up a small PR based on the above that should unblock this use case here; thanks again for the suggestion! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition @kavitha186 ; I think we can merge this increment already, even if there's potentially still those unused fields to clear out, as this is already a nice improvement.
Thanks @timtebeek for merging this Pr. I will pass boolean flag from this RemoveBoolVariation as true and will implement the get visitor on Removeunusedlocalvariable to check for any builder or any other methods used from LDContext. |
Hi @kavitha186 that should mostly be covered already with the changes I added here. But let me know if there's anything left to do still! |
yes looks like all covered . Will take up next item from the issues..thanks |
@timtebeek I would like to first fix this one 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.
I'm thinking to approach this as below
Please confirm if it would work or should I create a new recipe to handle below special cases while removing local variable.