New Line at the End of file
In most cases, it is recommended to include a new line at the end of text / source files. POSIX compliance is one historical reason, but it also ensures that tools, for example cat, return cleanly at the end of their output:
Not so nice
$ cat file-without-newline-at-eol.js
reticulateSplines()
.then( stopSlackingOff );
commenceLoafing();yourcoolhostname:yourcoolproject yourcoolusername$
Your prompt ends up combined with the last line as the end of the source file.
Better!
$ cat file-with-newline-at-eol.js
compileKernel()
.then( continueBuilding );
waitForIt();
yourcoolhostname:yourcoolproject yourcoolusername$
Your prompt stands alone on a new line.
Tools
- The wpcalypso eslint config deems it an error if files do not "end with a newline (LF)"
- Prettier reformats files to add a newline at the end "by design"
- Most (if not all) major editors have settings to add newlines at the end of source files. For example:
- nano: enabled by default. To disable, you supply the
-Lflag - Atom: enabled by default. To disable, you override settings for the core package,
whitespace
- nano: enabled by default. To disable, you supply the