Skip to content

NewlineAtEndOfFile=lf does not create error when file uses crlf #4074

@jayvdb

Description

@jayvdb

http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile

NewlineAtEndOfFile only checks the end of the file for bytes matching the EOL type , for the length of the EOL type.

As lf is only one byte, it does not detect that the previous byte cr before the lf.
Therefore a crlf combination at EOF is accepted as a valid match for lineSeparator=lf

$ cat TestConfig.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
  "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
  "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

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

$ echo -ne "1\r\n" > newline.txt 

$ hd newline.txt 
00000000  31 0d 0a                                          |1..|
00000003


$ java -jar checkstyle-7.7-all.jar -c TestConfig.xml newline.txt 
Starting audit...
Audit done.

Expected: violation as last line is "0d0a" but "0a"(lf) is expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions