Since Checkstyle 5.0
Rationale: If a source file becomes very long it is hard to understand. Therefore, long classes should usually be refactored into several individual classes that focus on a specific task.
To configure the check to accept files with up to 2000 lines:
<module name="Checker"> <module name="FileLength"/> </module>
Example:
public class Example1 { public void myTest() { // small class less than 2000 lines String test = "Some content"; } }
To configure the check to accept files with up to 5 lines:
<module name="Checker"> <module name="FileLength"> <property name="max" value="5"/> </module> </module>
Example:
public class Example2 { public void myTest() { // small class with more than 5 lines String test = "Some content"; // there is violation } }
To configure the check to accept files with up to 5 lines and with txt extension only:
<module name="Checker"> <module name="FileLength"> <property name="max" value="5"/> <property name="fileExtensions" value="txt"/> </module> </module>
Example:
public class Example3 { public void myTest() { // small class with more than 5 lines String test = "Some content"; // no violation as only txt files are validated } }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.sizes