Skip to content

Conversation

@Anmol202005
Copy link
Collaborator

Fixes: #124

Implemented recipe for NewlineAtEndOfFile: https://checkstyle.sourceforge.io/checks/misc/newlineatendoffile.html

@Anmol202005 Anmol202005 force-pushed the eol branch 15 times, most recently from 8b311bc to e5cc5a3 Compare October 30, 2025 19:29
@Anmol202005
Copy link
Collaborator Author

Finally got CI GREEN.

@rdiachenko pls review :)

@Anmol202005
Copy link
Collaborator Author

@romani @rdiachenko ping.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for delay ...

items:

final Space eof = sourceFile.getEof();
final String lastWhitespace = eof.getLastWhitespace();

if (!lineEnding.equals(lastWhitespace)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not trust checkstyle violation ? or it is save check in case of second execution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a check for second execution.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last:

final String expectedLineEnding = determineLineEnding(sourceFile);

final Space eof = sourceFile.getEof();
final String lastWhitespace = eof.getLastWhitespace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on windonws machine new line is \r\n, what value lastWhitespace will take in this case: \n or \r\n? Please also add a test case to cover this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in real case scenario it will take \r\n. for the test cases and CI we have used git attributes to define line endings.

Also added a new test case :)

final String lastWhitespace = eof.getLastWhitespace();

if (!expectedLineEnding.equals(lastWhitespace)) {
final List<Comment> comments = eof.getComments();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this special analysis with comments? Can you explore simpler solution? Idially, given end of fille we should check if the file doesn't end with expectedLineEnding then simply append it.

Copy link
Collaborator Author

@Anmol202005 Anmol202005 Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdiachenko this is the AST structure requirement. that's where the whitespace is stored when comments exist !!

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need explicitly add this recipe to checkstyle main repo config to be executed by CI ?

thansk a lot for your work.

@Anmol202005
Copy link
Collaborator Author

Anmol202005 commented Nov 19, 2025

Do we need explicitly add this recipe to checkstyle main repo config to be executed by CI ?

No
https://github.com/checkstyle/checkstyle/blob/50aa6850b3b6e1cf3fd7ac0238ba269b01753471/rewrite.yml#L6-L11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement recipe for NewlineAtEndOfFile

3 participants