-
Notifications
You must be signed in to change notification settings - Fork 6
Issue #124: Implement recipe for NewlineAtEndOfFile #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
8b311bc to
e5cc5a3
Compare
|
Finally got CI GREEN. @rdiachenko pls review :) |
|
@romani @rdiachenko ping. |
romani
left a comment
There was a problem hiding this 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:
.gitattributes
Outdated
| src/test/resources/org/checkstyle/autofix/recipe/newlineatendoffile/** -text | ||
|
|
||
| # Force LF line endings for diff test files | ||
| *.diff text eol=lf No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add \n to end of this file,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
| J result = (J) tree; | ||
|
|
||
| if (tree instanceof JavaSourceFile) { | ||
| final JavaSourceFile sourceFile = (JavaSourceFile) tree; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (tree instanceof JavaSourceFile sourceFile) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
| } | ||
|
|
||
| private String determineLineEnding(JavaSourceFile sourceFile) { | ||
| return switch (lineSeparatorConfig.toLowerCase()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do toLowerCase() in constructor to do this only in whole execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
| final Path filePath = sourceFile.getSourcePath().toAbsolutePath(); | ||
|
|
||
| if (hasViolation(filePath)) { | ||
| final String lineEnding = determineLineEnding(sourceFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reanem lineEnding to expectedLineEnding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
| final Space eof = sourceFile.getEof(); | ||
| final String lastWhitespace = eof.getLastWhitespace(); | ||
|
|
||
| if (!lineEnding.equals(lastWhitespace)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| private boolean hasViolation(Path filePath) { | ||
| return violations.removeIf(violation -> { | ||
| return violation.getFilePath().endsWith(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we do removal from collection of violation ?
is this prevention of double execution ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do this since we already do a check. reverted this.
Fixes: #124
Implemented recipe for NewlineAtEndOfFile: https://checkstyle.sourceforge.io/checks/misc/newlineatendoffile.html