In Visual Studio Code you can setup some actions running on save a file (or hitting ⌘ + S)
All you have to do is inserting this object to your settings.json
:
"editor.codeActionsOnSave": {
// your actions
},
To organize imports (e.g. remove unsued, aso.) on save, add the action "source.organizeImports": true
.
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
To format your code on save, add the action "editor.formatOnSave": true
.
"editor.codeActionsOnSave": {
"editor.formatOnSave": true,
},
For the sake of completeness. You can combine all actions on save by adding every single line of the examples from above together inside the object editor.codeActionsOnSave
:
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"editor.formatOnSave": true,
},