GeezerVison is showing github.com — [java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons · Issue #2145 · pmd/pmd
[java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons #2145Activityadangel commented on Dec 6, 2019 Thanks for the suggestion. Do you have a special reason, why to do this? changed the title [-][java] PositionLiteralsFirst rules must be merged into one.[/-] [+][java] Merge rules PositionLiteralsFirstInComparisons with *CaseInsensitiveComparisons[/+] on Dec 6, 2019linusjf commented on Dec 6, 2019 It's confusing to the user. I was confused when I first saw it. I used one, then discovered the other. Now, I use both.
Any particular reason why users would use one and not the other?
Implementation-wise, is it difficult to wrap two rules into one? I don't think it is.
Secondly, isn't the team working on rationalising rules for version 7? This will help.
Do we even care if it's case sensitive or not? The purpose is to prevent NullPointerExceptions.
Why ask me this question? Are you questioning the rest of the people posting bug reports or suggestions?
What kind of a question is that? Is it concerning PMD? If it is, I'd like to see PMD improve as a product and hopefully the people working on it as well. jsotuyod commented on Dec 9, 2019 This is actually a very reasonable idea…
Both rules are exactly identical except one checks for ends-with(@Image, '.equalsIgnoreCase') and the other for ends-with(@Image, '.equals'). I'd even go further and merge them without a property, I see no reason a developer may want to do this for one but not for the other… Reacted by Linus Fernandes adangel commented on Dec 9, 2019
Why ask me this question? Are you questioning the rest of the people posting bug reports or
suggestions?
I asked, because you didn't give any explanation at all. I could come up with my own assumptions, why this makes sense, but without being explicit of why you suggest what, it's just questionable. If I do something, I'd like to know why. linusjf commented on Dec 9, 2019 Ok. My fault. I tend to assume that others see my point of view or will realize that if they ask themselves why. I understand that's not always the case. It takes time to sometimes arrive at the same conclusion.
Are the reasons provided above not sufficient? Do you need more justification? linusjf commented on Dec 10, 2019 Author show commentMore actions adangel commented on Dec 16, 2019
Are the reasons provided above not sufficient? Do you need more justification?
That's fine, thanks. John-Teng commented on May 10, 2020 @adangel I'd like to work on this as my first contribution! adangel commented on May 12, 2020 @John-Teng Awesome!
We might have a single rule for the following cases (all related to comparison):
String s = "foo";
if (s.equals("bar")) { // currently PositionLiteralsFirstInComparisons
// should be:
"bar".equals(s);
}
if (s.equalsIgnoreCase("bar")) { // currently PositionLiteralsFirstInCaseInsensitiveComparisons
// should be:
"bar".equalsIgnoreCase(s);
}
if (s.compareTo("bar") > 0) { // currently missing - note: that needs special explanation, since switching the operands changes the result
// should be:
if ("bar".compareTo(s) < 0) { ... }
}
if (s.compareToIgnoreCase("bar") > 0) { // currently missing
// should be:
if ("bar".compareToIgnoreCase(s) < 0) { ... }
}
if (s.contentEquals("bar")) { // currently missing
// should be:
"bar".contentEquals(s);
}
I'd start with creating a new rule and afterwards retiring the existing rules.
Here are some pointers for writing rules:
John-Teng commented on May 12, 2020 @adangel thanks for the pointers! I have submitted PR #2478, please take a look and provide feedback. Once this PR looks good, I'll open another PR that deprecates the existing rules. changed the title [-][java] Merge rules PositionLiteralsFirstInComparisons with *CaseInsensitiveComparisons[/-] [+][java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons[/+] on May 14, 2020John-Teng commented on May 18, 2020 I've opened up PR #2493 to deprecate the existing rules.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|