-
Notifications
You must be signed in to change notification settings - Fork 117
Remove all UseVarFor* from JavaBestPractices #1043
Description
I'm classifying this as a bug as I think that the current functionality is a mistake, although the behavior is as expected given the choice that was made previously.
Local-Variable Type Inference is a good feature, there are cases where it is very reasonable to use it. The JavaBestPractices recipe calls these cases "non-controversial uses", but I think that while it's uncontroversial that, in these cases, var can be used, it's a lot more controversial to say that for these cases it should be used, everywhere, indiscriminately.
- The Local Variable Type Inference Style Guidelines are very clear that "There’s no blanket rule for when it should and shouldn’t be used".
- As Java 10+ Local-Variable Type Inference should be used
RSPEC-6212#217 points it its OP, general use ofvarhad been removed from the "Sonar way" profile.
I have no problem with these UseVarFor* recipes, some teams might want to use them, I might use them at some point, but having them in the JavaBestPractices feels contrary to what is expected given the name of the recipe.
What version of OpenRewrite are you using?
I am using
- rewrite-maven-plugin 6.35.0
- rewrite-migrate-java 3.31.3
What is the smallest, simplest way to reproduce the problem?
class A {
void foo(String bar) {
int i = 5;
}
}What did you expect to see?
No change
What did you see instead?
int changed to var
Are you interested in contributing a fix to OpenRewrite?
I could remove the five lines from the JavaBestPractices recipe, and maybe create a new composite recipe that activates those five "uncontroversial" recipes, so to get the current functionality back you'd only have to do something like
<recipe>org.openrewrite.java.migrate.lang.var.UseVar</recipe>
<recipe>org.openrewrite.java.migrate.JavaBestPractices</recipe>Metadata
Metadata
Assignees
Labels
Type
Projects
Status