How to suppress all file checks in Checkstyle?

I am doing an override for a third-party class, and I want to suppress all the checks for it (since I only support it until the patch is accepted).

Is there a way to suppress all checks for a file?

I tried using "*" but it failed.

+41
java checkstyle
Jun 18 '09 at 12:36
source share
6 answers

I don't know if you use the command line or in the IDE, but basically you need a suppresions file. If you manually edit the Checkstyle configuration file, add a new module to it:

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

Your mysuppression.xml might look something 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="TheClassToIgnore\.java" checks="[a-zA-Z0-9]*"/> </suppressions> 

The value of the " files " attribute is basically a regular expression for your source files, and the value for the " checks " attribute is a regular expression for which checks to skip (" [a-zA-Z0-9]* " basically means skip all), This is the sample you're looking for, I think?

+47
Jun 19 '09 at 6:11
source share

I was able to suppress the checks in the file by adding the SuppressionCommentFilter tag to my checks.xml:

First, I added the FileContentHolder tag as a child of the TreeWalker tag:

 <module name="TreeWalker"> ... <module name="FileContentsHolder"/> ... </module> 

Then I added the SuppressionCommentFilter parameter in the checks.xml file:

 <module name="SuppressionCommentFilter"/> 

In each file I wanted to suppress, I inserted the following comment on the first line of the file:

 // CHECKSTYLE:OFF 
+21
Jun 19 '09 at 17:13
source share

aberrant80 answer really helped. Using his tooltip - using matching regular expression patterns, I was also able to suppress the control style for the entire package by adding it to the checkstyle-suppressions.xml file. E.g. to skip checkstyle checks for all automatically generated java files in the jaxb package,

  <suppressions> <suppress checks="[a-zA-Z0-9]*" files="[\\/]jaxb[\\/]" /> </suppressions> 
+15
Feb 23 2018-12-23T00:
source share

If you use the Checkclipse Eclipse plugin for Checkstyle, you can enable or exclude file templates (including directories) by going to the Checkclipse> File Filter tab in the project properties. For example, my project contains src and test directories at the top level. I want Checkstyle to apply only to files in the src directory (excluding test ), so I added an include template that looks like this:

 src/.+java$ 

As you can see, it uses regex style syntax to specify the template.

+7
Jun 18 '09 at 13:39
source share

It is possible to ignore write-protected files. Or files in a package.

0
Jun 18 '09 at 12:42
source share

If you do not want to have a group of files as part of a verified project, you can filter these files so that they are not scanned by creating a file filter

The file filter uses a regular expression to determine which files should be excluded. The regular expression works with the full file name - because of this, you can also exclude entire folders. In this case, you can exclude the whole package if you want.

If you advertise a bit on Google, you'll probably find some Checkstyle Configurationtytty configuration files that have examples of what you're looking for. After that, I would advise you to do this - save it as a little template so that you can reference it in future situations.

0
Jun 19 '09 at 5:46
source share



All Articles