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:
- the latter (
formatOnSave
) only formats code, - while the former (
codeActionsOnSave
) can run one or several commands on the code, commands which might not be related to formatting.
As noted by Umair Ishaq in the comments:
The actual schema for
editor.codeActionOnSave
, showing it accepts an array, can be found here atsrc/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts