LineEnding

Since Checkstyle 13.3.0

Description

Checks whether file uses a specific line-ending sequence (LF, CRLF, or CR).

A violation is reported for each line whose actual line ending does not match the configured one.

Notes

Files containing mixed line endings may produce multiple violations, one for each non-matching line.

Properties

name description type default value since
fileExtensions Specify the file extensions of the files to process. String[] all files 13.3.0
lineEnding Set lineEnding. LineEndingOption lf 13.3.0

Examples

To configure the check to enforce LF (Unix-style) line endings:


<module name="Checker">
  <module name="LineEnding"/>
</module>

Example:


public class Example1 { // ␊   // ok line ending is LF
  public void method() { // ␊  // ok line ending is LF
    int x = 1; // ␊            // ok line ending is LF
  } // ␊                       // ok line ending is LF
} // ␊                         // ok line ending is LF

To configure the check to enforce CRLF (Windows-style) line endings:


<module name="Checker">
  <module name="LineEnding">
    <property name="lineEnding" value="crlf"/>
  </module>
</module>

Example:


public class Example2 { // ␍␊  // ok line ending is CRLF
  public void method() { // ␍␊ // ok line ending is CRLF
    int x = 1; // ␍␊           // ok line ending is CRLF
  } // ␍␊                      // ok line ending is CRLF
} // ␍␊                        // ok line ending is CRLF

To configure the check to enforce CR line endings:


<module name="Checker">
  <module name="LineEnding">
    <property name="lineEnding" value="cr"/>
  </module>
</module>

Example (file with LF line endings - violations):


public class Example3 {  // ␊ // violation 'Expected line ending for file is CR, but LF is detected.'
  public void method() { // ␊ // violation 'Expected line ending for file is CR, but LF is detected.'
    int x = 1; // ␊           // violation 'Expected line ending for file is CR, but LF is detected.'
  } // ␊                      // violation 'Expected line ending for file is CR, but LF is detected.'
} // ␊                        // violation 'Expected line ending for file is CR, but LF is detected.'

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

Parent Module

Checker