Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55281

restore lint enforcement of newlines at EOF for source files

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: Internal Code
    • Labels:
      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.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: