-
Notifications
You must be signed in to change notification settings - Fork 73
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
Java 10+ Local-Variable Type Inference should be used RSPEC-6212
#217
Comments
This would be straightforward to implement with OpenRewrite, it can exist as a standalone recipe. This leverage |
I'd like to work on this one and would like to clarify a few things. To be sure, do we want to implement RSPEC-6212 100% Sonar like? I would argue against it because it also suggests using |
Things I thought about, anything to add?
|
Thank you for your offer to help out on this one! I think you have a decent list of restrictions in place already to limit applicability. I'd indeed say not to use this for primitives, and even then it's still not always a clear improvement, which makes it a tricky recipe to recommend. Might be good to take into account the upcoming changes for OpenRewrite 8.0, which will have change the applicability tests for instance. Maybe we can start with a suite of unit tests and do a round of feedback on that? Then we can more clearly decide which cases are worth covering, before we look into the finer details of the recipe implementation. Feel free to to open a draft pull request with what cases you would (not) want to cover as part of this work! |
|
Good point, not all usages of primitives are bad.
So for primitives I suggest:
|
What about not correctly used generics?
Maybe via configuration? |
I think it might be best to keep this recipe focused on applying Instead it's probably better to surface other "sub-optimal" code patterns such as incorrect generics, in a separate recipe, and give users the choice there what they want to do: find only with a marker, or transform in some way. Probably a find-only recipe could be helpful to start with, then run that through Moderne on a broad list of projects, and deduce possible remediations from there, if and only if broadly applicable. Does that sounds like a decent approach for this one? |
* Add test and dummy recipe as baseline for #217 * Add tests for primitives and var keywords Group Tests for var keywords Add use to Recipe name * Refine and group tests as nested tests * Refine and group tests as nested tests * Implement UseVarKeyword reciepe except for generics Fix format in tests and disable generics tests * Add Todo to implement generics and explicitly skip them for the moment * UseVarKeyword: rename variables and improve null-checking in type checking. UseVarKeywordTest: rename method * Add handling of static and instance initializer blocks * add skipping of generics types * replace * Extract handling of primitive variable definition for local variable type inference into own recipe * Extract handling of Object variable definition for local variable type inference into own recipe * Add Recipe that combines Object and Primitive handling for var. Refactor DeclarationCheck to be package private Utility. Prio used UseVarKeywordTest remains as prove of correct refactoring. * add licences to source code * Add DocumentedExample to tests and remove Examples from Recipe * simplify null handling and reorder hot paths * Apply suggestions from code review Co-authored-by: Knut Wannheden <knut.wannheden@gmail.com> * remove NotNull Annotaions * rework determination if inside method and add test for edgecase * use configuration UseJavaVersion * Update license header --------- Co-authored-by: Knut Wannheden <knut.wannheden@gmail.com>
This is controversial and the Sonar team had to remove it from the default "Sonar Way" profile
https://rules.sonarsource.com/java/tag/java10/RSPEC-6212
The text was updated successfully, but these errors were encountered: