Prevent auto-formatting of VSCode when saving from deleting last new line

I use the latest VSCode function called formatOnSave , which is very cool.
I have one tiny problem: formatting program seeks to remove the new line at the end of the file json, for example packages.json.

My linter wants these new lines at the end of the file, and so do I.

Is there a parameter or method that allows me to tell the formatter to keep new lines at the end of files?

Related problem:

+10
source share
2 answers

This parameter was added after the release of version 1.8 of November 2016 :

New editor settings

  • files.insertFinalNewline - automatically add a new line at the end of files when saving.
+11
source

  My linter needs these new lines at the end of the file, and so do I.

VSCode ESLint has an option called autoFixOnSavethat you can try. Depending on your workflow, the ESLint CLI also has an option --fixthat you can link with git hook.

If you are just looking for some reasonable defaults , here they are:

"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
0
source

Source: https://habr.com/ru/post/1657965/


All Articles