EmptyForInitializerPad

Since Checkstyle 3.4

Description

Checks the padding of an empty for initializer; that is whether a white space is required at an empty for initializer, or such white space is forbidden. No check occurs if there is a line wrap at the initializer, as in

for (
      ; i < j; i++, j--)
        

Properties

name description type default value since
option Specify policy on how to pad an empty for iterator. PadOption nospace 3.4

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="EmptyForInitializerPad"/>
  </module>
</module>
        

Example:

class Example1 {
  int i = 0;
  void example() {
    for ( ; i < 1; i++ );  // violation '';' is preceded with whitespace'
    for (; i < 2; i++ );
    for (;i<2;i++);
    for ( ;i<2;i++);       // violation '';' is preceded with whitespace'
    for (
          ; i < 2; i++ );
  }
}
        

To configure the check to require white space at an empty for iterator:

<module name="Checker">
  <module name="TreeWalker">
    <module name="EmptyForInitializerPad">
      <property name="option" value="space"/>
    </module>
  </module>
</module>
        

Example:

class Example2 {
  int i = 0;
  void example() {
    for ( ; i < 2; i++ ) { };
    for (; i < 2; i++ ) { };    // violation '';' is not preceded with whitespace'
    for (;i<2;i++) { };         // violation '';' is not preceded with whitespace'
    for ( ;i<2;i++) { };
    for (
          ; i < 2; i++ );
  }
}
        

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