Newer versions of VS code include a new codeActionsOnSave
options. It is recommanded to setup Eslint for example. However I don't understand the difference with previously existing formatOnSave
option, nor their relationship with the defaultFormater
option, plugins like Prettier and ESLint, and VS Code default behavior.
"Fix" seems more complete, but disabling "format" will not always format my code on save. I also tend to have conflicts between Eslint and Prettier formatting...
Basically it is unclear to me how to set a proper VS Code formatting configuration, that respects project settings (TypeScript, Eslint, Prettier etc. that can be activated/deactivated depending on the project), due to a lack of understanding about the VS Code settings.
Run Code Actions on save# The new editor.codeActionsOnSave setting lets you configure a set of Code Actions that are run when a file is saved.
Before getting deeper into the specifics, the main distinction between these editors is that Visual Studio is a full-fledged Integrated Development Environment (IDE), while Visual Studio Code is a rich text editor.
Brief: VSCodium is a clone of Microsoft's popular Visual Studio Code editor. It's identical to VS Code with the single biggest difference that unlike VS Code, VSCodium doesn't track your usage data. Microsoft's Visual Studio Code is an excellent editor not only for web developers but also for other programmers.
I'm trying to get my VS Code to run ESLint and Prettier together properly as well.
Then VSCode 1.44 (March 2020) would highlight another difference between codeActionsOnSave
and formatOnSave
:
Explicit ordering for editor.codeActionsOnSave
You can now set
editor.codeActionsOnSave
to an array of code actions to execute in order. You can use this to guarantee that a specific code action is always run before or after another one that may conflict with itThe following
editor.codeActionsOnSave
will always runOrganize Imports
followed byFix All
once organize imports finishes:"editor.codeActionsOnSave": [ "source.organizeImports", "source.fixAll" ]
But the main difference between codeActionsOnSave
and formatOnSave
remains that:
formatOnSave
) only formats code,codeActionsOnSave
) can run one or several commands on the code, commands which might not be related to formatting.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With