In software development it’s generally considered good practice (and sometimes necessary) to add a blank line at the end of a code file. In VS Code we can configure the IDE to force a newline at the end of a file every time we save. There are several ways to set this up, as discussed below.
Global Settings
To apply a newline at file end for any file saved in the IDE, open VS Code and:
Navigate to File (‘Code’ on Mac) > Preferences > Settings.
In the search bar, type Insert Final Newline. You should see a single setting appear, where you can check the box to activate this functionality.
Project Settings
If your project is using a dedicated settings file at .vscode/settings.json, you can add the line “files.insertFinalNewline”: true within the settings JSON object in this file. Adding this line should apply a newline to the end of any file in the project when saving.