NoLineWrap

Since Checkstyle 5.8

Description

Checks that chosen statements are not line-wrapped. By default, this Check restricts wrapping import and package statements, but it's possible to check any statement.

Properties

Examples

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;

class                        // violation 'should not be line-wrapped'
  Example1 {

  public                     // violation 'should not be line-wrapped'
    Example1() {}
  public void                // violation 'should not be line-wrapped'
    doSomething() {}
}

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 com.puppycrawl.tools. // violation 'should not be line-wrapped'
  checkstyle.api.AbstractCheck;

import static java.math.     // ok, STATIC_IMPORT is not part of the tokens
  BigInteger.ZERO;

class
  Example2 {

  public
    Example2() {}
  public void
    doSomething() {}
}

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:


package com.puppycrawl.      // ok, PACKAGE_DEF is not part of the tokens
  tools.checkstyle.checks.whitespace.nolinewrap;

import com.puppycrawl.tools. // ok, IMPORT is not part of the tokens
  checkstyle.api.AbstractCheck;

import static java.math.     // ok, STATIC_IMPORT is not part of the tokens
  BigInteger.ZERO;

class                        // violation 'should not be line-wrapped'
  Example3 {

  public                     // violation 'should not be line-wrapped'
    Example3() {}
  public void                // violation 'should not be line-wrapped'
    doSomething() {}
}

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.whitespace.NoLineWrapCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker