How can I suppress specific Checkstyle rules in Eclipse?
Asked Answered
S

1

6

I'm trying to use suppression filter but an unexpected error occurs.

Following is an error message.

"cannot initialize module SuppressionFilter - Cannot set property 'file' in module SuppressionFilter to 'checkstyle-suppressions.xml': unable to find checkstyle-suppressions.xml - Document root element "suppressions", must match DOCTYPE root "module"."

Could you let me know how can I resolve this error?

Followings are a configuration file and a suppression file contents which I used. I configured the suppression filter through eclipse menu(windows > preferences > checkstyle > configure > known modules Filter > Suppression Filter > add)

======================================

configuration file is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="severity" value="warning"/>
    <module name="TreeWalker">
        <module name="MagicNumber">
            <property name="ignoreNumbers" value="-1, 0, 1"/>
        </module>
    </module>
</module>

===================================

suppression filter file is ...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">         

<suppressions>
    <suppress checks="MagicNumberCheck"
              files="Home.java"
              lines="350-370"/>
</suppressions>
Sheepskin answered 24/7, 2013 at 8:0 Comment(0)
A
6

Your suppression filter file uses the 1.1 syntax, but claims to be using the newer 1.3 syntax. Exchange the header like so:

<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

Also, your configuration file must reference the suppression filter. Add a module definition like this (add it before the last closing </module> tag, not under Treewalker):

<module name="SuppressionFilter">
    <property name="file" value="${workspace_loc}/MyProject/suppressions.xml"/>
</module>

Using the ${workspace_loc} variable makes sure that this works even when you copy or rename the workspace.

Aili answered 24/7, 2013 at 19:9 Comment(2)
Thanks alot for your help. Both configuration and suppression filter is working well.Sheepskin
Thanks! Here's official documentation about that: checkstyle.sourceforge.net/config.html And example file - checkstyle.sourceforge.net/files/suppressions_none.xmlIllusionary

© 2022 - 2024 — McMap. All rights reserved.