VSCode: Auto Format on Save (Prettier)
These are the settings that I use in tandem with ESLint and Prettier.
- Go to
File > Preferences > Settings - Search for
On Save - Under
Editor: Code Actions On SaveclickEdit in settings.json - Set the following:
"editor.codeActionsOnSave": [ "source.organizeImports", "source.fixAll.eslint" ]
This will organize imports alphabetically (source.organizeImports) and use eslint to fix any auto-fixable errors. Using prettier this will take care of formatting as well.
For organizing imports, I initially was only using source.organizeImports but this was removing the trailing commas on imports which conflicted with my prettier settings. By following it with source.fixAll.eslint, the prettier rules fix this at the same time.