Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Newline at end of file

📅 2016-Dec-29 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ eof, newline ⬩ 📚 Archive

Many Linux tools and compilers that process text files require the text file to end with a newline. This is simply because they are designed to process a series of lines, each ending with a newline. That means, the last line of the file should also end in a newline.

If the file does not end with a newline, then C++ compilers and other tools complain with errors such as No newline at end of file.

How do you end up with a file that does not end in newline? If you use tools that are written for other platforms like Windows or are cross-platform, those might not follow the rule of ending the last line with a newline. The latest culprit who I found doing this mistake was the Visual Studio Code editor. Editors like Vim, which come from a Unix heritage, just do not allow you to save without a newline.

In Visual Studio Code, I set the files.insertFinalNewline option to true to fix this mistake.

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧