6

I have a java class with > 2000 lines, and I have Checkstyle configured to allow lines upto 2000. I want to override this Checkstyle property only for one file. How can I do that?

2

2 Answers 2

3

In Checkstyle code itself there is TokenTypes class that is huge.

Solution that Checkstyle developers use currently is to suppress that file by specifying it in suppressions.xml:

<suppressions>
    <suppress checks="FileLength"
              files="TokenTypes.java"
              lines="1"/>

This mechanism is called SuppressionFilter.

Sign up to request clarification or add additional context in comments.

2 Comments

what does lines="1" do?
the lines is intended to target what line the error is appearing on. In this case, it isn't required. See checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/…
1

Just place this comment as the very first line of your class file:

// CSOFF: FileLength

1 Comment

This is a good answer, but in order to work you should configure SuppressionCommentFilter with offCommentFormat and onCommentFormat, or you can use directly the default values with CHECKSTYLE:OFF and CHECKSTYLE:ON instead the CSOFF value. See checkstyle.sourceforge.io/filters/suppressioncommentfilter.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.