When I run checkstyle through pre-commit, it gives the following warnings:
checkstyle...............................................................Failed
- hook id: checkstyle
- exit code: 4
Starting audit...
[ERROR] /some_path/AnotherSomeFile.java:1: File length is 1,950 lines (max allowed is 1,000). [FileLength]
[ERROR] /some_path/someFile.java:1: File length is 1,676 lines (max allowed is 1,000). [FileLength]
Audit done.
Checkstyle ends with 4 errors.
I have disabled the other checkstyle errors for those files by including the line:
<module name="SuppressionCommentFilter"/>
inside the <module name="TreeWalker"> module (and including // CHECKSTYLE:OFF at the top of each file that I want to ignore with checkstyle. (As explained in this answer. However, the
<module name="FileLength">
<property name="max" value="1000"/>
</module>
check needs to be above/outside of the TreeWalker module inside the checkstyle.xml file. That means the SuppressionCommentFilter module does not apply to the FileLength module inside the checkstyle.xml.
Attempts
- I tried moving the
FileLengthmodule inside theTreeWalkermodule, and that is not allowed. - I tried copying the
SuppressionCommentFilterinto the parent ofTreeWalker/at the same level/below theFileLengthcheck module, and that is not allowed.
Question
How can I exclude the FileLength module for 4 files at src/some_path/file_one.java, src/some_path/file_two.java etc. inside the checkstyle.xml?
You can use the SuppressionFilter to exclude the
FileLengthcheck for specific files. The suppression filter accepts asuppressions.xmlconfig file. The files to be excluded will be supplied as a regex within this config file. The config files would look something like below:checkstyle.xml:
suppressions.xml: