-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Internal Code
-
None
-
Fully Compatible
-
Service Arch 2021-03-22, Service Arch 2021-04-05
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.
- is related to
-
SERVER-71739 Move check newlines lint to clang-tidy
- Closed
- related to
-
SERVER-72810 add "files.insertFinalNewline" to linux-virtual-workstation.code-workspace
- Closed