LineEnding
Since Checkstyle 12.4.0
Description
Files containing mixed line endings may produce multiple violations, one for each line that does not match the configured line ending.
Notes
This check treats each line independently and reports violations per line.
Properties
| name | description | type | default value | since |
|---|---|---|---|---|
| fileExtensions | Specify the file extensions of the files to process. | String[] | all files |
12.4.0 |
| lineEnding | Set lineEnding. | LineEndingOption | lf |
12.4.0 |
Examples
To configure the check to enforce LF (Unix-style) line endings:
<module name="Checker">
<module name="LineEnding"/>
</module>
Example:
public class Example1 { // ␊
public void method() { // ␊
int x = 1; // ␊
} // ␊
} // ␊ // ok, file uses LF line endings.
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 { // ␍␊
public void method() { // ␍␊
int x = 1; // ␍␊
} // ␍␊
} // ␍␊ // ok, file uses CRLF line endings.
To configure the check to enforce LF line endings:
<module name="Checker">
<module name="LineEnding">
<property name="lineEnding" value="crlf"/>
</module>
</module>
Example (file with CRLF line endings - violations):
public class Example3 { // ␍␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
public void method() { // ␍␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
int x = 1; // ␍␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
} // ␍␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
} // ␍␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
To configure the check to enforce CRLF line endings:
<module name="Checker">
<module name="LineEnding">
<property name="lineEnding" value="crlf"/>
</module>
</module>
Example (file with LF line endings - violations):
public class Example4 { // ␊ // violation 'Expected line ending for file is CRLF(\\r\\n), but LF(\\n) is detected.'
public void method() { // ␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
int x = 1; // ␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
} // ␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) is detected.'
} // ␊ // violation 'Expected line ending for file is LF(\\n), but CRLF(\\r\\n) 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






