Skip to content

Issue #18619: Add expected separator to NewlineAtEndOfFileCheck violation - #18972

Merged
mahfouz72 merged 1 commit into
checkstyle:masterfrom
mdhamed238:issue-18619-newline-error-message
Jul 20, 2026
Merged

mahfouz72 merged 1 commit into
checkstyle:masterfrom
mdhamed238:issue-18619-newline-error-message

Conversation

@mdhamed238

Copy link
Copy Markdown
Contributor

Issue: #18619

Problem:
When lineSeparator is set to lf, cr, or crlf and a file does not end with
the expected separator (e.g. ends with CR when LF is expected, or has no newline at
all), the check emitted the generic message "File does not end with a newline." — giving
no indication of what separator was actually expected. This was misleading, especially
when the file does end with some newline, just not the right kind.

Fix:
Added a new message key noNewlineAtEOFWithSeparator ("File does not end with a
newline '{0}'.") used when lineSeparator is one of the specific options: lf, cr,
or crlf. The original noNewlineAtEOF ("File does not end with a newline.") is
preserved for the generic options lf_cr_crlf (default) and system, where naming a
specific separator in the message would be misleading. All 9 locale message files were
updated with translations of the new key.

Testing:
Updated NewlineAtEndOfFileCheckTest#testCrEndingWhenLfExpected and
testNoNewlineLfAtEndOfFile to assert the new parameterized message. Added
Example7.java (cr separator, no newline) and Example8.java (crlf separator,
no newline) with corresponding testExample7 and testExample8 in
NewlineAtEndOfFileCheckExamplesTest, covering the two previously untested
violation paths for cr and crlf separators.

@mdhamed238

Copy link
Copy Markdown
Contributor Author

Hi @romani,

Added noNewlineAtEOFWithSeparator message key, all 9 locale files updated, and previously untested cr/crlf paths are now covered. CI is green, ready for review.

Thank you.

@romani

romani commented Apr 13, 2026

Copy link
Copy Markdown
Member

please make PR ready for review.

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch 4 times, most recently from 8a0f16e to 7759199 Compare April 13, 2026 22:29
@mdhamed238

Copy link
Copy Markdown
Contributor Author

Hi @romani,
All CI checks pass, except "Generate pitest-misc report" which cause of failure is unclear to me. Could you help me understand what is expected here?

@romani

romani commented Jul 18, 2026

Copy link
Copy Markdown
Member

@mdhamed238 , please continue this PR also.

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch 7 times, most recently from 0a0c088 to beaa740 Compare July 19, 2026 02:55

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mahfouz72 will do deeper look
after quick look:

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch from beaa740 to e98aeda Compare July 19, 2026 03:18

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one more items:

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch 2 times, most recently from abf0996 to 1a54394 Compare July 19, 2026 03:43
@mdhamed238 mdhamed238 changed the title Issue #18619: Add expected separator to NewlineAtEndOfFileCheck viola… Issue #18619: Add expected separator to NewlineAtEndOfFileCheck violation Jul 19, 2026
@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch 2 times, most recently from 85c1db8 to fec37a7 Compare July 19, 2026 04:14

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

last:

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch 2 times, most recently from c5ef63e to 24c9517 Compare July 19, 2026 05:31

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

doc polishing

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch from 23a9594 to bba6471 Compare July 19, 2026 06:32
@romani

romani commented Jul 19, 2026

Copy link
Copy Markdown
Member

GitHub, generate website

@romani

romani commented Jul 19, 2026

Copy link
Copy Markdown
Member

./mvnw clean verify on local before push to github, to NOT waste time of CI

@romani

romani commented Jul 19, 2026

Copy link
Copy Markdown
Member

[ERROR] XdocsPagesTest.validateExampleSectionSeparation:2767 Missing <hr class="example-separator"/> between Example4 and Example6 in file: src/site/xdoc/checks/misc/newlineatendoffile.xml.template

hmm, please make code at XdocsPagesTest.validateExampleSectionSeparation to exclude this newlineatendoffile Example4-6 from from this validation, it is exceptional case, we group them as represent the same config but different files.

@romani

romani commented Jul 19, 2026

Copy link
Copy Markdown
Member

Github, generate report for NewlineAtEndOfFile/Example3

@github-actions

Copy link
Copy Markdown
Contributor

@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch from bba6471 to 48e8421 Compare July 19, 2026 11:58
@mdhamed238
mdhamed238 force-pushed the issue-18619-newline-error-message branch from 48e8421 to 86af391 Compare July 19, 2026 12:22
@mdhamed238

Copy link
Copy Markdown
Contributor Author

Hi @romani,
All concerns have been addressed and CI is green.
Thanks a lot for the review.

@mdhamed238

Copy link
Copy Markdown
Contributor Author

I see that 4 commits have been merged into master in the meantime. Even though there's no conflict, should I rebase with master again?

@romani

romani commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

I see that 4 commits have been merged into master in the meantime. Even though there's no conflict, should I rebase with master again?

only before next push to GitHub from your side (usually happens when you do extra chnage).

@romani

romani commented Jul 19, 2026

Copy link
Copy Markdown
Member

GitHub, generate website

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks a lot

@mahfouz72 mahfouz72 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot!

@mahfouz72
mahfouz72 merged commit ac23dde into checkstyle:master Jul 20, 2026
131 checks passed
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.

3 participants