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

name description type default value since
skipAnnotations Specify whether annotations on the previous line should be checked as errors. boolean true 12.3.0
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

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;

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 {

  @Deprecated
  public Example5() {
  }

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

  class Bar {

    public // violation 'should not be line-wrapped'
      Bar() {
    }

    @Deprecated
    public void fun() {
    }
  }
}

To configure the check to force no line-wrapping annotations:


<module name="Checker">
  <module name="TreeWalker">
    <module name="NoLineWrap">
      <property name="skipAnnotations" value="false"/>
      <property name="tokens" value="CLASS_DEF"/>
    </module>
  </module>
</module>

Example:


@Deprecated // violation 'should not be line-wrapped'
public class Example6 {
}

Examples of not line-wrapped statements (good case):


import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import static java.math.BigInteger.ZERO;
        

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.

Package

com.puppycrawl.tools.checkstyle.checks.whitespace

Parent Module

TreeWalker