Visitar URL original
Enhance RemoveUnusedLocalVariables to support filtering by type by bgalek · Pull Request #563 · openrewrite/rewrite-static-analysis · GitHub
Skip to content

Enhance RemoveUnusedLocalVariables to support filtering by type - #563

Merged
timtebeek merged 6 commits into
openrewrite:mainfrom
bgalek:RemoveUnusedLocalVariablesByType
May 19, 2025
Merged

timtebeek merged 6 commits into
openrewrite:mainfrom
bgalek:RemoveUnusedLocalVariablesByType

Conversation

@bgalek

@bgalek bgalek commented May 19, 2025 •

Copy link
Copy Markdown
Contributor

What's changed?

This PR enhances the RemoveUnusedLocalVariables recipe in OpenRewrite by introducing a new configuration option: onlyRemoveVariablesOfType. This option allows users to specify a list of fully qualified class names; only unused local variables of those types will be considered for removal.

What's your motivation?

This change addresses an important scalability concern in large codebases. Removing all unused local variables often results in extensive, unrelated changes across a project, making code reviews cumbersome.

Checklist

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 19, 2025
@bgalek
bgalek force-pushed the RemoveUnusedLocalVariablesByType branch from f459270 to 3d3b26f Compare May 19, 2025 14:25
@bgalek

bgalek commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

@timtebeek check it out ;)

@timtebeek
timtebeek self-requested a review May 19, 2025 14:58
@timtebeek timtebeek added the enhancement New feature or request label May 19, 2025
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite May 19, 2025

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 328-345
    • lines 660-659
    • lines 705-721
    • lines 1254-1273
    • lines 1306-1305
    • lines 2337-2336
    • lines 2352-2364
    • lines 2801-2800
    • lines 2820-2831

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the help here! I've added a few small polishing commits, but other than that it looks great.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 328-345
    • lines 660-659
    • lines 705-721
    • lines 1254-1273
    • lines 1306-1305
    • lines 2232-2231
    • lines 2337-2336
    • lines 2352-2364
    • lines 2801-2800
    • lines 2820-2831

timtebeek and others added 3 commits May 19, 2025 18:58
Co-authored-by: iddeepak <87892182+iddeepak@users.noreply.github.com>
@timtebeek
timtebeek merged commit bfcf6d5 into openrewrite:main May 19, 2025
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 19, 2025

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/resources/META-INF/rewrite/examples.yml
    • lines 328-345
    • lines 660-659
    • lines 705-721
    • lines 1254-1273
    • lines 1306-1305
    • lines 2338-2337
    • lines 2353-2365
    • lines 2802-2801
    • lines 2821-2832

@bgalek

bgalek commented May 19, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks! See You in the next PR :))

this.withSideEffects = withSideEffects;
}

@InlineMe(replacement = "new RemoveUnusedLocalVariables(ignoreVariablesNamed, null, withSideEffects)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract is that the value corresponds exactly to the body, so this(...) rather than new RemoveUnusedLocalVariables(...).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had doubted about that, but seeing how this is likely to be called from outside the class I opted for the in-my-eyes safer constructor calls that ought to be a drop in elsewhere. If that's wrong then we can change it still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Enhance RemoveUnusedLocalVariables to support filtering by variable type

4 participants