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 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.
- Since:
- 13.3.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LineEndingOptionDefault line ending 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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckLineEndings(LineEndingOption expected, byte... content) Checks that the file content uses the configured line ending and logs a violation for each line that does not match.private voidlogIncorrectLineEnding(int line, LineEndingOption wrongLineEnding) Logs an incorrect line ending detected at the given line.protected voidprocessFiltered(File file, FileText fileText) Called to process a file that matches the specified file extensions.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
A key is pointing to the warning message text in "message.properties" file.- See Also:
-
lineEnding
Default line ending LF.
-
-
Constructor Details
-
LineEndingCheck
public LineEndingCheck()
-
-
Method Details
-
setLineEnding
Setter to set lineEnding.- Parameters:
ending- string of value LF or CRLF- Since:
- 13.3.0
-
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.
-
checkLineEndings
Checks that the file content uses the configured line ending and logs a violation for each line that does not match.- Parameters:
expected- the expected line endingcontent- the file content as bytes
-
logIncorrectLineEnding
Logs an incorrect line ending detected at the given line.- Parameters:
line- the line number where the issue was foundwrongLineEnding- the detected incorrect line ending
-