Checkstyle - Exclude folder

时光怂恿深爱的人放手 提交于 2019-11-30 00:34:11

问题


I want to ignore a specific folder (named generated-sources) from my checkstyle reports, because they are generated.

I'm using eclipse-cs for displaying my violations.

i added a suppressionfilter to my xml:

<module name="SuppressionFilter">
    <property name="file" value=".\suppressions.xml"/>
</module>

my suppressions.xml looks like this:

<?xml version="1.0"?>

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

<suppressions>
    <suppress files="\*generated-sources\*\*\.\*" checks="[a-zA-Z0-9]*"/>
</suppressions>

but it is not working. any ideas?


回答1:


<suppress files="[\\/]generated-sources[\\/]" checks="[a-zA-Z0-9]*"/>

this works :)




回答2:


Additionally to the answer from Philipp, I had to use an absolute pathname ( :-( ) for the suppression file:

<module name="SuppressionFilter">
    <property name="file" value="/Users/xxx/workspace/suppressions.xml"/>
</module>

Looks like the Checkstyle plugin is not using the project home directory.

(at least under eclipse luna / Mac OS X)




回答3:


As pointed by Thomas Welsch in his answer, there appears to be a problem with using relative pathname for the suppression xml file.

For gradle builds, This gist suggests a workaround:

in build.gradle:

checkstyle {
    // use one common config file for all subprojects
    configFile = project(':').file('config/checkstyle/checkstyle.xml')
    configProperties = [ "suppressionFile" : project(':').file('config/checkstyle/suppressions.xml')]
 }

in checkstyle.xml:

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

(the default value allows IDE plugins, that do not have the gradle variable sorted out, to work correctly)



来源:https://stackoverflow.com/questions/18013322/checkstyle-exclude-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!