-
Notifications
You must be signed in to change notification settings - Fork 61
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
#448
Fix PMD rule LiteralsFirstInComparisons
for compareTo*
and contentEquals
#448
Conversation
1f33b73
to
b38ff0a
Compare
I need to fix my setup to get this running. It should be almost there, right? I think it's better to deliver something now rather than waiting longer. Feel free to take over and provide early feedback if this seems like the right direction. Thanks |
…ns-for-compareTo-and-contentEquals' into Fix-PMD-rule-LiteralsFirstInComparisons-for-compareTo-and-contentEquals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to takeover and give feedback, thx.
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
Outdated
Show resolved
Hide resolved
…compareTo-and-contentEquals
compareTo*
and contentEquals
compareTo*
and contentEquals
LiteralsFirstInComparisons
for compareTo*
and contentEquals
public class A { | ||
{ | ||
String s = null; | ||
if(s.compareTo("test")) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should add & then invert any comparison with < 0
here for instance, as indicated in #362 (comment). As it stands I think we're using an int
in an if
. 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to keep the flip for compareTo
, we have to also migrate the comparison. Otherwise, we would also flip the semantic, see #442.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ATM, the implementation exclude the flip of <
and >
needed for compareTo
, this can be done later.
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
e493fd6
to
decf84b
Compare
…compareTo-and-contentEquals # Conflicts: # src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
aa6fce0
to
0ae11da
Compare
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
deepseek managed to inline while chatGPT failed ^^ |
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
This reverts commit 74cd190.
cdf95f7
to
46f143b
Compare
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
Thanks for the work here @punkratz312 ; The automated suggestions are coming in because there's still differences seen after running the following against your branch: https://docs.openrewrite.org/recipes/recipes/rewrite/openrewriterecipebestpractices |
of course my friend. done and dusty |
@timtebeek the auto correction does not work. i applied it once before and wonder why. its. not working. see the. ci. My commit is green. The github action is failing. checking each commit its failing on compile lvl. ![]() |
a65c948
to
46f143b
Compare
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
- src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
- lines 25-26
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
- src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
- lines 25-26
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java
Outdated
Show resolved
Hide resolved
…java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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/java/org/openrewrite/staticanalysis/EmptyBlock.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FallThrough.java
- lines 19-19
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 20-20
- src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
- lines 25-26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed some test that were already covered and merged the two visitors.
Great work!
LiteralsFirstInComparisons
forcompareTo*
andcontentEquals
#362