Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress specific Checkstyle rules in Eclipse?

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>
like image 877
500004dolkong Avatar asked Jul 24 '13 08:07

500004dolkong


People also ask

How do I turn off Checkstyle rules?

Then to disable Checkstyle, you use //CHECKSTYLE:OFF and //CHECKSTYLE:ON (default values) in your code.

How do I remove Checkstyle from Eclipse?

Show activity on this post. In latest eclipse version(9/2014) we have to visit Help -> Eclipse Market and go to installed tab. Then select uninstall. After uninstallation this will ask for a eclipse restart.

How do I use Checkstyle in eclipse?

Right-click on the project. Click on Checkstyle and Activate Checkstyle . (Or, if there is no Checkstyle entry, click on Properties and then select “Checkstyle”, check “Checkstyle active…” and click on OK .)


1 Answers

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.

like image 116
barfuin Avatar answered Sep 20 '22 21:09

barfuin