GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #2145

New issue
Copy link
New issue
Copy link
Closed
Closed
[java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons#2145
Copy link
Assignees
John-Teng
Labels
a:suggestionAn idea, with little analysis on feasibility, to be consideredgood first issueA great starting point for new contributors
Milestone
6.24.0

Description

@linusjf
linusjf
opened on Dec 4, 2019
Issue body actions

Affects PMD Version:
6.20.0

Rule:
PositionLiteralsFirstInComparisons
PositionLiteralsFirstInCaseInsensitiveComparisons

Description:
The above two rules must be merged into one with a property to decide whether to ignore case-sensitive or not.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Activity

  1. adangel
    added
    a:suggestionAn idea, with little analysis on feasibility, to be considered
    on Dec 6, 2019
  2. adangel commented on Dec 6, 2019

    @adangel
    adangel
    on Dec 6, 2019
    Member
    More actions

    Thanks for the suggestion. Do you have a special reason, why to do this?

  3. adangel
    changed the title [-][java] PositionLiteralsFirst rules must be merged into one.[/-] [+][java] Merge rules PositionLiteralsFirstInComparisons with *CaseInsensitiveComparisons[/+] on Dec 6, 2019
  4. linusjf commented on Dec 6, 2019

    @linusjf
    linusjf
    on Dec 6, 2019
    Author
    More actions

    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.

  5. jsotuyod commented on Dec 9, 2019

    @jsotuyod
    jsotuyod
    on Dec 9, 2019
    Member
    More actions

    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
  6. adangel commented on Dec 9, 2019

    @adangel
    adangel
    on Dec 9, 2019
    Member
    More actions

    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.

  7. linusjf commented on Dec 9, 2019

    @linusjf
    linusjf
    on Dec 9, 2019
    Author
    More actions

    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?

  8. linusjf commented on Dec 10, 2019

    @linusjf
    linusjf
    on Dec 10, 2019 · Hidden as off-topic
    Author
    show commentMore actions
  9. adangel commented on Dec 16, 2019

    @adangel
    adangel
    on Dec 16, 2019
    Member
    More actions

    Are the reasons provided above not sufficient? Do you need more justification?

    That's fine, thanks.

  10. adangel
    added
    good first issueA great starting point for new contributors
    on Dec 16, 2019
  11. John-Teng commented on May 10, 2020

    @John-Teng
    John-Teng
    on May 10, 2020
    Contributor
    More actions

    @adangel I'd like to work on this as my first contribution!

  12. adangel commented on May 12, 2020

    @adangel
    adangel
    on May 12, 2020
    Member
    More actions

    @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:

    • https://pmd.github.io/latest/pmd_userdocs_extending_writing_rules_intro.html
    • current rule:
      • https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsRule.java, https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractPositionLiteralsFirstInComparisons.java
      • test: https://github.com/pmd/pmd/blob/master/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsTest.java
      • test cases: https://github.com/pmd/pmd/blob/master/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/PositionLiteralsFirstInComparisons.xml
    Reacted by John-Teng
  13. adangel
    assigned
    John-Teng
    on May 12, 2020
  14. John-Teng commented on May 12, 2020

    @John-Teng
    John-Teng
    on May 12, 2020
    Contributor
    More actions

    @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.

  15. adangel
    changed the title [-][java] Merge rules PositionLiteralsFirstInComparisons with *CaseInsensitiveComparisons[/-] [+][java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons[/+] on May 14, 2020
  16. adangel
    added this to the 6.24.0 milestone on May 18, 2020
  17. John-Teng commented on May 18, 2020

    @John-Teng
    John-Teng
    on May 18, 2020
    Contributor
    More actions

    I've opened up PR #2493 to deprecate the existing rules.

  18. adangel
    closed this as completedin b49279don May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @John-Teng
    John-Teng

Labels

a:suggestionAn idea, with little analysis on feasibility, to be consideredgood first issueA great starting point for new contributors

Type

No type

Projects

No projects

    Milestone

    • 6.24.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.