Difference between codeActionsOnSave and formatOnSave in VS Code

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 it

The following editor.codeActionsOnSave will always run Organize Imports followed by Fix 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 at src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)