Since Checkstyle 5.8
name | description | type | default value | since |
---|---|---|---|---|
tokens | tokens to check | subset of tokens IMPORT , STATIC_IMPORT , PACKAGE_DEF , CLASS_DEF , METHOD_DEF , CTOR_DEF , ENUM_DEF , INTERFACE_DEF , RECORD_DEF , COMPACT_CTOR_DEF . | PACKAGE_DEF , IMPORT , STATIC_IMPORT . | 5.8 |
To configure the check to force no line-wrapping in package and import statements (default values):
<module name="Checker"> <module name="TreeWalker"> <module name="NoLineWrap"/> </module> </module>
Examples of line-wrapped statements (bad case):
package com.puppycrawl. // violation 'should not be line-wrapped' tools.checkstyle.checks.whitespace.nolinewrap; import com.puppycrawl.tools. // violation 'should not be line-wrapped' checkstyle.api.AbstractCheck; import static java.math. // violation 'should not be line-wrapped' BigInteger.ZERO;
Examples:
package com.puppycrawl.tools.checkstyle. // violation 'should not be line-wrapped' checks.whitespace.nolinewrap; import java.lang.Object; import java.lang. // violation 'should not be line-wrapped' Integer; import static java.math. // violation 'should not be line-wrapped' BigInteger.TEN;
Example:
package com.puppycrawl.tools.checkstyle.checks.whitespace.nolinewrap; import java.lang. // violation 'should not be line-wrapped' Boolean; import static java.math.BigInteger.ONE;
To configure the check to force no line-wrapping only in import statements:
<module name="Checker"> <module name="TreeWalker"> <module name="NoLineWrap"> <property name="tokens" value="IMPORT"/> </module> </module> </module>
Example:
package com.puppycrawl. // OK, PACKAGE_DEF is not part of the tokens tools.checkstyle.checks.whitespace.nolinewrap; import java.io.*; import java.lang. // violation 'should not be line-wrapped' Boolean; import static java.math. // OK, STATIC_IMPORT is not part of the tokens BigInteger.ZERO;
To configure the check to force no line-wrapping only in class, method and constructor definitions:
<module name="Checker"> <module name="TreeWalker"> <module name="NoLineWrap"> <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF"/> </module> </module> </module>
Example:
import com.puppycrawl.tools.checkstyle.api.AbstractCheck; import static java.math.BigInteger.ZERO; class // violation 'should not be line-wrapped' Example5 { public Example5() { } public static void // violation 'should not be line-wrapped' doSomething() { } class Bar { public // violation 'should not be line-wrapped' Bar() { } public void fun() { } } }
Examples of not line-wrapped statements (good case):
import com.puppycrawl.tools.checkstyle.api.AbstractCheck; import static java.math.BigInteger.ZERO;
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.whitespace