[SERVER-55281] restore lint enforcement of newlines at EOF for source files Created: 17/Mar/21  Updated: 29/Oct/23  Resolved: 25/Mar/21

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-72810 add "files.insertFinalNewline" to lin... Closed
is related to SERVER-71739 Move check newlines lint to clang-tidy Closed
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2021-03-22, Service Arch 2021-04-05
Participants:

 Description   

A newline is a LF,CR,or CRLF, but we specifically want to enforce Unix LF newlines to avoid diff churn and other patching/tools issues.

(Update: Git is handling the Windows-vs-Unix (CRLF-vs-LF) issue pretty well and no action needs to be taken in the linter for that)

Lack of terminating newline affects the real results of scripting tools like cat and wc -l (line count), and is a source of diff/git churn. It's also something compilers can warn about, as such source files are technically not valid text files as defined by POSIX (they are now tolerated by C++11, but why push our luck).

We used to check for this until the linter was rewritten in 2019.
All 71 current instances of missing trailing newlines came in after that.

To identify these files:

find src/mongo -type f -name '*.py' -o -name '*.idl' -o -name '*.cpp' -o -name '*.h' |
while read fn ; do tail -n1 $fn | read _ || echo $fn ; done

Easiest fix is probbaby to append an empty echo.
So add a repair stage to the pipeline:

find src/mongo -type f -name '*.py' -o -name '*.idl' -o -name '*.cpp' -o -name '*.h' |
while read fn ; do tail -n1 $fn | read _ || echo $fn ; done |
while read fn ; do echo "fixing $fn"; echo >> $fn; done

Added a note to https://wiki.corp.mongodb.com/display/HGTC/Visual+Studio+Code+for+Server+Development
about how to configure VSCode so that it won't produces these kinds of files anymore.



 Comments   
Comment by Githook User [ 25/Mar/21 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-55281 lint for newline violations
Branch: master
https://github.com/mongodb/mongo/commit/3022c66b2af7049f4096cc7117f94f5194c5e1e2

Comment by Githook User [ 25/Mar/21 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@gmail.com', 'username': 'BillyDonahue'}

Message: SERVER-55281 newline-terminate all source files
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/8fd8c10188f02103d11275838a0f10e02d6c5ed6

Comment by Louis Williams [ 18/Mar/21 ]

Does VSCode produce invalid text files that don't have the terminating newline?

Unfortunately, yes. But it seems like there is a way to work around this.

I misunderstood the purpose of this ticket. This ticket aims to add missing terminating newlines to files. It does not try to enforce specific LF usages throughout files, which Git already does.

Comment by Billy Donahue [ 18/Mar/21 ]

The linter I'm talking about doesn't fix anything.

Does VSCode produce invalid text files that don't have the terminating newline?
There's a setting to make it enforce this if it resaves files that already have the problem.
https://stackoverflow.com/questions/44704968/visual-studio-code-insert-new-line-at-the-end-of-files

The CRLF translation is already handled by git, I think.

Generated at Thu Feb 08 05:36:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.