GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||
GeezerVison is showing github.com — [java] New rule: AssertEqualsArgumentOrder by zbynek · Pull Request #6713 · pmd/pmd Conversation
|
|
Compared to main: (comment created at 2026-06-19 17:09:29+00:00 for 8cc3eaa) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
You might want to add support for TestNG, spring-test, and JSONAssert |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
34fc162 to
fe550f1
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Since there is no extra issue, I assume, that you added this rule because you have a real need for it...
And since there is no extra issue, can you update the PR description to describe the new rule? Like we require for issues/new-rule-feature-request (-> https://github.com/pmd/pmd/blob/main/.github/ISSUE_TEMPLATE/2new_rule.md ). There is no need to create an extra issue for that, the PR is enough. But having the description correct helps later on for documentation. E.g. I will add this PR in the release notes under "java-errorprone" with a link to this PR and it would be good if the PR description is complete... Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@adangel I checked how other frameworks do this (links in initial comment) and I'm no longer sure this should be a single rule -- the indication is the same (constant being used as "actual"), but the implications are different: in some cases the error message is confusing, in others it's likely a copy-paste error making the whole test method pointless. The upside of having one rule for both is that we don't have to inspect the same nodes twice. Btw. the trivial assertions with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'd say the scope of the rule is fine as it is. What you have right now is AFAICT equivalent to MisorderedAssertEqualsArguments/AssertEqualsArgumentOrderChecker, isn't it? The other linked checks could serve as ideas for other rules. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Well right now it also detects the comparison of two literals, which falls under something like EqualsWithItself. The question is whether we ever want to have a rule for detecting |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ah, I see. Looking at the rule description...
That indeed "feels" like two different things. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ba6097a to
2324d7b
Compare
In general, I like the rule. It will be useful (and we should enable it for our own dogfood ruleset). I think, we should keep it as one rule - a rule that concentrates on problems around using assertEquals. If we ever do quickfix/autofix (which would require to know which solution is correct), we can split the rule later at anytime.
Maybe we can describe the rule a bit more general like "There is an assert equals statement, that doesn't look right". Thanks to your comments about the parameter order, I remembered now the problem when switching from Junit4 to Junit Jupiter: If - for some reason - you provided a message, but use the same value for the message as expected, then upgrading to JUnit Jupiter by just statically importing the other assertEquals gives you the problem "expected and actual are the same"... I remember, I had to touch every assertEquals, when we migrated to Junit 5 in PMD... So, maybe, we just shouldn't suggest to replace the assertEquals with "fail" or remove it. Maybe we should just point out, that "expected" and "actual" parameters are the same - and this not something you usually want. We could of course check, whether we have 3 parameters and suggest to move the first parameter to the end (assuming this was a JUnit4 message parameter). But I wouldn't do that and keep it simple. But I see, you already updated the rule description... Alternative rule name suggestions: AssertEqualsArgumentMismatch, PotentialAssertEqualsArgumentMismatch, UnusualAssertEquals rule violation message suggestion: assertEquals() called with swapped arguments or constants also the rule example should probably be updated to not only include constants, but also include the swapped expected/actual case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good.
The rule name is good actually, no need to change.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Andreas Dangel <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.