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 — [apex] Support suppression via //NOPMD · Issue #1087 · pmd/pmd

[apex] Support suppression via //NOPMD #1087

New issue
Copy link
New issue
Copy link
Closed
#2279
Closed
[apex] Support suppression via //NOPMD#1087
#2279
Copy link
Labels
an:enhancementAn improvement on existing features / rulesgood first issueA great starting point for new contributorsin:documentationAffects the documentation [doc]
Milestone
6.22.0

Description

@0cv
0cv
opened on May 9, 2018
Issue body actions

Affects PMD Version:
All versions

Rule:
//NOPMD

Description:
//NOPMD has no effect

Code Sample demonstrating the issue:

This will fail:

return new Map<Id, SObject> (Database.query(//NOPMD
        soqlQuery
)); 

This will work:

return new Map<Id, SObject> (Database.query(NOPMD
        soqlQuery
)); 

Obviously, this cannot compile on Salesforce... But could it be that comments are ignored?

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

Reacted by Eric Kintzer

Activity

  1. jsotuyod commented on May 9, 2018

    @jsotuyod
    jsotuyod
    on May 9, 2018
    Member
    More actions

    The comment-based suppression is not supported in Apex. Actually it's not supported in any language but Java. I reckon the documentation is not sufficiently clear on this regard.

    For Apex you can only suppress warnings by use of the @SuppressWarnings annotation: https://pmd.github.io/pmd-6.3.0/pmd_userdocs_suppressing_warnings.html#annotations

  2. jsotuyod
    added
    in:documentationAffects the documentation [doc]
    a:bugPMD crashes or fails to analyse a file.
    on May 9, 2018
  3. jsotuyod
    changed the title [-][apex] - //NOPMD is not working[/-] [+][apex] //NOPMD is not working[/+] on May 9, 2018
  4. 0cv commented on May 9, 2018

    @0cv
    0cv
    on May 9, 2018
    Author
    More actions

    Thanks for the quick answer. Java, along maybe EcmaScript? I've the feeling that there is something implemented here

    pmd/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java

    Line 69 in f6b5193

    suppressMap = new HashMap<>();
    which is missing here

    pmd/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java

    Line 53 in f6b5193

    suppressMap = new HashMap<>();

    But I couldn't figure out the apex.jorje methods (to get the Comments) to build something similar.

  5. jsotuyod commented on May 9, 2018

    @jsotuyod
    jsotuyod
    on May 9, 2018
    Member
    More actions

    Yes, ES supports it too. For Apex we can't. The Jorje Parser drops all comments, they are not made available for us.

  6. yippie commented on May 10, 2018

    @yippie
    yippie
    on May 10, 2018
    More actions

    This is really unfortunate as it throws a LOT of false positives (particularly around CRUD checks and test assertion checks)

    Reacted by Christophe Vidal, SnugSFBay, Jordan Pike and Francesco Carmagnola
  7. jsotuyod commented on May 10, 2018

    @jsotuyod
    jsotuyod
    on May 10, 2018
    Member
    More actions

    @yippie if you have false positives, you should report them back to us so we can fix them rather than have them suppressed.

  8. rsoesemann commented on May 10, 2018

    @rsoesemann
    rsoesemann
    on May 10, 2018
    Member
    More actions

    @yippie Comments are ignored by the Apex parser we use (the one from Salesforce). Therefore // NOPMD will not work. Use the @SupressWarnings annotation instead. Details here: https://pmd.github.io/pmd-6.0.0/pmd_userdocs_suppressing.html

    FYI: @jsotuyod

    Reacted by Eric Kintzer
  9. 0cv commented on May 14, 2018

    @0cv
    0cv
    on May 14, 2018
    Author
    More actions

    @rsoesemann - thanks (but in case of classes, this is not really selective to suppress all the warning of a given class). But anyway, can you suggest how to suppress warnings from Components and VF Pages?

    1- <!-- NOPMD --> doesn't seem to work (neither do <!-- //NOPMD --> nor //NOPMD, nor NOPMD)
    2- Adding @SuppressWarnings('PMD'), within or not <!-- ... --> is not doing anything either.

    Reacted by Eric Kintzer
  10. jsotuyod commented on May 14, 2018

    @jsotuyod
    jsotuyod
    on May 14, 2018
    Member
    More actions

    @Krisa we can't currently suppress warnings in VF. Using <!-- NOPMD --> should be possible, but some coding is needed to support it. If anyone is up to the challenge, look me up on gitter and I'll gladly give you pointers

    Reacted by Robert Sösemann
  11. jsotuyod
    added
    good first issueA great starting point for new contributors
    on Jun 23, 2018
  12. jsotuyod commented on Sep 23, 2018

    @jsotuyod
    jsotuyod
    on Sep 23, 2018
    Member
    More actions

    Thanks for @jeffhube's work on #1314 we now have the groundwork to include support for // NOPMD on Apex.

    If anyone is up for the challenge, please contact me and I'll help you figure out the way forward.

  13. marcalbaladejo commented on Jan 2, 2019

    @marcalbaladejo
    marcalbaladejo
    on Jan 2, 2019
    More actions

    Hi @jsotuyod, the support for //NOPMD has been finally added for APEX? or will it be shortly?
    thanks!

  14. jsotuyod commented on Jan 2, 2019

    @jsotuyod
    jsotuyod
    on Jan 2, 2019
    Member
    More actions

    @marcalbaladejo it's not been added yet.

    The core PMD team is currently focused on gearing up for PMD 7.0.0, which is mainly breaking changes we have accumulated over the last year or so.

    6.11.0 is also in the works, but mainly contains:

    • Community contributions
    • Actual bug fixes (ie: crashes upon certain code structures)
    • Deprecations we want to include in 6.x before removal in 7.0.0
    • Low hanging fruit we come upon on our daily PMD usage

    If anyone is interested on working on this and submit a PR, we can gladly assist in the process.

  15. marcalbaladejo commented on Jan 3, 2019

    @marcalbaladejo
    marcalbaladejo
    on Jan 3, 2019
    More actions

    Thanks @jsotuyod!, for now I've done my own sfdx plugin that cleans up the output checking against the source code, to find the suppress markers.

    Reacted by tomaswrk19 and Edmondo Porcu
  16. adangel
    added
    an:enhancementAn improvement on existing features / rules
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Feb 13, 2020
  17. adangel
    added this to the 6.22.0 milestone on Feb 13, 2020
  18. adangel
    changed the title [-][apex] //NOPMD is not working[/-] [+][apex] Support suppression via //NOPMD[/+] on Feb 13, 2020
  19. adangel
    closed this as completedin #2279on Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rulesgood first issueA great starting point for new contributorsin:documentationAffects the documentation [doc]

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.22.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.