Domanda

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>
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top