Class NewlineAtEndOfFileCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable, FileSetCheck

    public class NewlineAtEndOfFileCheck
    extends AbstractFileSetCheck

    Checks that there is a newline at the end of each file.

    An example of how to configure the check is:

     <module name="NewlineAtEndOfFile"/>

    This will check against the platform-specific default line separator.

    It is also possible to enforce the use of a specific line-separator across platforms, with the 'lineSeparator' property:

     <module name="NewlineAtEndOfFile">
       <property name="lineSeparator" value="lf"/>
     </module>

    Valid values for the 'lineSeparator' property are 'system' (system default), 'crlf' (windows), 'cr' (mac), 'lf' (unix) and 'lf_cr_crlf' (lf, cr or crlf).

    • Field Detail

      • MSG_KEY_UNABLE_OPEN

        public static final java.lang.String MSG_KEY_UNABLE_OPEN
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_KEY_NO_NEWLINE_EOF

        public static final java.lang.String MSG_KEY_NO_NEWLINE_EOF
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NewlineAtEndOfFileCheck

        public NewlineAtEndOfFileCheck()
    • Method Detail

      • processFiltered

        protected void processFiltered​(java.io.File file,
                                       FileText fileText)
        Description copied from class: AbstractFileSetCheck
        Called to process a file that matches the specified file extensions.
        Specified by:
        processFiltered in class AbstractFileSetCheck
        Parameters:
        file - the file to be processed
        fileText - the contents of the file.
      • setLineSeparator

        public void setLineSeparator​(java.lang.String lineSeparatorParam)
        Sets the line separator to one of 'crlf', 'lf','cr', 'lf_cr_crlf' or 'system'.
        Parameters:
        lineSeparatorParam - The line separator to set
        Throws:
        java.lang.IllegalArgumentException - If the specified line separator is not one of 'crlf', 'lf', 'cr', 'lf_cr_crlf' or 'system'