rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Clean up recipe to rename local variable and method parameter names as camel case.

Open traceyyoshima opened this issue 4 years ago • 2 comments

Create a recipe that renames local variables and method parameter names to match naming convention. Default Regex Pattern: ^[a-z][a-zA-Z0-9]*$

see: https://rules.sonarsource.com/java/RSPEC-117?search=local%20variable

traceyyoshima avatar May 10 '21 16:05 traceyyoshima

This requires: https://github.com/openrewrite/rewrite/issues/533.

traceyyoshima avatar May 11 '21 00:05 traceyyoshima

Partially, implemented in: https://github.com/openrewrite/rewrite/commit/22f06ffb030e65f5cb1749e7d455c2e59e6119b7.

Currently, the recipe does not rename all local variables. The recipe does not rename fields that are local members of a class. since that would be pretty complex.

The recipe also prevents renames of variables if the result exists anywhere in the class to prevent unexpected name shadows.

It is possible to refactor the hasNameSet to use cursors and determine if will not create a shadow of a name, and rename variables safely.

traceyyoshima avatar May 28 '21 00:05 traceyyoshima