Class LineEndingCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
com.puppycrawl.tools.checkstyle.checks.LineEndingCheck
- All Implemented Interfaces:
Configurable,Contextualizable,FileSetCheck
Checks whether the files have a specific line ending (LF or CRLF).
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.
- Since:
- 12.4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LineEndingOptionDefault line separator LF.static final StringA key is pointing to the warning message text in "message.properties" file.static final StringA key is pointing to the warning message text in "message.properties" file.static final StringA key is pointing to the warning message text in "message.properties" file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckCrlfLineEndings(byte... content) Checks that the file content uses CRLF line endings.private voidcheckLfLineEndings(byte... content) Checks that the file content uses LF line endings.protected voidprocessFiltered(File file, FileText fileText) Called to process a file that matches the specified file extensions.private voidreadAndCheckFile(File file) Reads the given file and checks its line endings against the configured line ending option.voidsetLineEnding(String ending) Setter to set lineEnding.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
addViolations, beginProcessing, destroy, finishProcessing, fireErrors, getFileContents, getFileExtensions, getMessageDispatcher, getTabWidth, getViolations, init, log, log, process, setFileContents, setFileExtensions, setMessageDispatcher, setTabWidthMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChildMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configureMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
-
Field Details
-
MSG_KEY_UNABLE_OPEN
A key is pointing to the warning message text in "message.properties" file.- See Also:
-
MSG_KEY_WRONG_ENDING_LF
A key is pointing to the warning message text in "message.properties" file.- See Also:
-
MSG_KEY_WRONG_ENDING_CRLF
A key is pointing to the warning message text in "message.properties" file.- See Also:
-
lineEnding
Default line separator LF.
-
-
Constructor Details
-
LineEndingCheck
public LineEndingCheck()
-
-
Method Details
-
processFiltered
Description copied from class:AbstractFileSetCheckCalled to process a file that matches the specified file extensions.- Specified by:
processFilteredin classAbstractFileSetCheck- Parameters:
file- the file to be processedfileText- the contents of the file.
-
setLineEnding
Setter to set lineEnding.- Parameters:
ending- string of value LF or CRLF- Since:
- 12.3.0
-
readAndCheckFile
Reads the given file and checks its line endings against the configured line ending option.- Parameters:
file- the file to be processed- Throws:
IOException- if an I/O error occurs while reading the file
-
checkLfLineEndings
Checks that the file content uses LF line endings.- Parameters:
content- the file content as a byte array
-
checkCrlfLineEndings
Checks that the file content uses CRLF line endings.- Parameters:
content- the file content as a byte array
-