No newline at the end of file ¯_(ツ)_/¯
I came to see this warning a few days back when I was seeing the git diff of a file in reaction to this I open the file and hit enter at the last line to my surprise the warning remains still the same.
What is a new line? The new line is usually \n, aka (CR or CRLF) at the end of the file. It's helpful to identify the last byte of the file.
Why it is good to have a new line at the end of the file?
Quoting from here
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character. Since this is a “shall” clause, we must emit a diagnostic message for a violation of this rule.
So, it turns out that, according to POSIX, every text file should end with a \n, or “newline” (not “a new line”) character. This acts as the eol, or the “end of line” character. It is a line “terminator”.
It's helpful to identify the end of file.
How to automatically add one with your favorite editor?
In your favorite editor, you can add newline automatically like this.
- Emacs : Add (setq require-final-newline t) to your .emacs or .emacs.d/init.el file.
- VS Code: set “files.insertFinalNewline”: true