Skip to content
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

[core] Force disable suppressions (PMD + CPD) #2896

Open
kloessst opened this issue Nov 2, 2020 · 2 comments
Open

[core] Force disable suppressions (PMD + CPD) #2896

kloessst opened this issue Nov 2, 2020 · 2 comments
Labels
an:enhancement An improvement on existing features / rules

Comments

@kloessst
Copy link

kloessst commented Nov 2, 2020

Description:
Hello,

PMD itself has the option -showsuppressed, to disable suppressions added to the code (via SupressWarnings or comment filtering). Does something similar exist for CPD? I would appreciate such a feature and would gladly contribute, if it doesn't exist yet.

Edit:
It seems like PMD uses this option to create another section in the report:

// suppressed violations
            if (showSuppressedViolations) {
                for (Report.SuppressedViolation s : suppressed) {
                    writeNewLine();
                    xmlWriter.writeStartElement("suppressedviolation");
                    xmlWriter.writeAttribute("filename", determineFileName(s.getRuleViolation().getFilename()));
                    xmlWriter.writeAttribute("suppressiontype", s.suppressedByNOPMD() ? "nopmd" : "annotation");
                    xmlWriter.writeAttribute("msg", s.getRuleViolation().getDescription());
                    xmlWriter.writeAttribute("usermsg", s.getUserMessage() == null ? "" : s.getUserMessage());
                    xmlWriter.writeEndElement();
                }
            }

Is it be possible to add an option which disables all suppressions completely?

Best regards,
Stefan

@kloessst kloessst added the a:question Request for information that doesn't necessarily entail changes to the code base label Nov 2, 2020
@kloessst kloessst changed the title CPD supressions CPD suppressions Nov 2, 2020
@kloessst kloessst changed the title CPD suppressions Disable CPD suppressions Nov 2, 2020
@adangel
Copy link
Member

adangel commented Nov 23, 2020

Right -showsuppressed shows all the violations, that are suppressed, which is almost what you want - but for PMD only.

You want to run PMD/CPD without any suppressions applied. I don't think, this is currently supported. Suppressions are basically always enabled.
Forced disabling suppressions sounds like a useful enhancement for some cases. Although I wonder, how it can be handled practically - it might be, if you have a big project, you'll be overwhelmed if all violations/duplications are reported.

CPD Suppression is described here: https://pmd.github.io/latest/pmd_userdocs_cpd.html#suppression
If you are interested in how much this is used in your code base, you could simply grep for "CPD-OFF"/"CPD-ON" or "CPD-START"/"CPD-END".

@kloessst
Copy link
Author

Thanks for your answer. We use static code analysis tools such as PMD in the context of programming exercises. We automatically assess student submissions by running tests and static code analysis tools. If there are options to circumvent violations, the students will find them 😄.
Theoretically, we could search for "CPD-OFF"/"CPD-ON" or "CPD-START"/"CPD-END" in student submissions and let them fail. Deactivating the suppressions with a configuration option would be much cleaner.

@adangel adangel changed the title Disable CPD suppressions [core] Force disable suppressions (PMD + CPD) Nov 25, 2020
@adangel adangel added an:enhancement An improvement on existing features / rules and removed a:question Request for information that doesn't necessarily entail changes to the code base labels Nov 25, 2020
adangel added a commit to adangel/pmd that referenced this issue Jan 28, 2024
This was not used and not tested.
To be readded with pmd#2736 and pmd#2896

Refs pmd#4348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
an:enhancement An improvement on existing features / rules
Projects
None yet
Development

No branches or pull requests

2 participants