Skip to content

Instantly share code, notes, and snippets.

@gcavalcante8808
Forked from camh-/eol-at-eof.md
Created June 22, 2023 19:39
Show Gist options
  • Save gcavalcante8808/618ca04f2baa7467cf7b8d45e5745995 to your computer and use it in GitHub Desktop.
Save gcavalcante8808/618ca04f2baa7467cf7b8d45e5745995 to your computer and use it in GitHub Desktop.
Please add newlines at end of files

See https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

A newline in a text file is a terminator, not a separator. This means each line should have a newline at the end of it, including the last line of the file.

Many editors automatically add the newline at the end of the file. Some do not. If you can configure your editor to ensure there is always a newline at the end of every line, please do so.

Because many editors do add this newline, if you commit a text file without it, when someone else edits the file, their editor will (correctly) add the newline. This causes a spurious diff in the file. Spurious diffs add a little bit more burden for reviewers, particularly if there are lots of files. The actual changes start to get hidden amongst the noise.

Having a newline at the end of the file allows files to be concatenated. If you miss the newline then when you concatenate files, the first line of the second file will be placed at the end of the last line of the first file, on the same line.

GitHub will show you that your file is missing a newline at the end of the file with a little red marker (that if you hover over it, it will say "No newline at end of file"). Please review your PR in the GitHub UI before asking someone else to. You should see this marker and correct it before asking for a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment