-
Notifications
You must be signed in to change notification settings - Fork 60
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
Fix PMD rule LiteralsFirstInComparisons
for compareTo*
and contentEquals
#362
Comments
I would love to volunteer and implement it if you could provide me with the snippet to flip the arguments. It should be very similar to my favorite rule, 1488 InlineVariable. https://docs.openrewrite.org/recipes/staticanalysis/inlinevariable. |
For the |
Thanks for the offer to help @punkratz312 ! As Knut has indicated rewrite-static-analysis/src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java Lines 32 to 34 in 2163f0f
I suppose Great to see you join the project and actively look for areas to improve. :) |
LiteralsFirstInComparisons
for compareTo*
and contentEquals
Thanks for the quick win! I'm looking forward to this fix in our codebase. When will it be available after the merge? |
Once merged it'll be available from our snapshot versions in a matter of minutes (provided the build succeeds). From there it'll get included in the next release; which is every other week on Wednesday, with the next one on the 23rd. Thanks again! |
|
A subtlety was missed in the earlier implementation, where the comparison used with |
Simply switch the arguments; that should be a very small change to make, just similar to the Inline Variable recipe.
What problem are you trying to solve?
https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#literalsfirstincomparisons
Describe the situation before applying the recipe
Describe the situation after applying the recipe
Further examples from the PMD:
The text was updated successfully, but these errors were encountered: