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

[doc] Improve documentation on usage of violationSuppressXPath #4901

Closed
mfvanek opened this issue Mar 28, 2024 · 2 comments · Fixed by #4961
Closed

[doc] Improve documentation on usage of violationSuppressXPath #4901

mfvanek opened this issue Mar 28, 2024 · 2 comments · Fixed by #4961
Labels
an:enhancement An improvement on existing features / rules in:documentation Affects the documentation
Milestone

Comments

@mfvanek
Copy link

mfvanek commented Mar 28, 2024

Is your feature request related to a problem? Please describe.
While migrating to PMD 7 I faced with extreme troubles how to rewrite old suppressions to a new style.
Example from docs doesn't work for me https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_userdocs_suppressing_warnings.html

<!-- doesn't work in PMD 7 -->
<property name="violationSuppressXPath" value="./ancestor::ClassDeclaration[contains(@Image, 'Bean')]"/>

Describe the solution you'd like
A good documentation with working examples

I found a clue in #4707

@mfvanek mfvanek added the an:enhancement An improvement on existing features / rules label Mar 28, 2024
@mfvanek
Copy link
Author

mfvanek commented Mar 28, 2024

Example 1

    <rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod">
        <properties>
            <property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['.*TestBase']"/>
        </properties>
    </rule>

transformed to

    <rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod">
        <properties>
            <property name="violationSuppressXPath" value=".[@SimpleName = 'TestBase'] | .[@SimpleName = 'BaseEntity']"/>
        </properties>
    </rule>

Example 2

    <rule ref="category/java/codestyle.xml/LinguisticNaming">
        <properties>
            <property name="checkSetters" value="false"/>
            <property name="violationSuppressXPath"
                      value="//ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='Test']"/>
        </properties>
    </rule>

transformed to

    <rule ref="category/java/codestyle.xml/LinguisticNaming">
        <properties>
            <property name="checkSetters" value="false"/>
            <property name="violationSuppressXPath"
                      value=".[pmd-java:hasAnnotation('org.junit.jupiter.api.Test')]"/>
        </properties>
    </rule>

@jsotuyod jsotuyod added the in:documentation Affects the documentation label Mar 29, 2024
@jsotuyod jsotuyod changed the title Improve documentation on usage of violationSuppressXPath [doc] Improve documentation on usage of violationSuppressXPath Mar 29, 2024
@zman0900
Copy link

Example 1 above doesn't work for me either. To exclude errors in classes with names ending in "Test", I found that this works:

<property name="violationSuppressXPath" value="./ancestor::ClassDeclaration[matches(@SimpleName, '^.*Test$')]" />

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 in:documentation Affects the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants