Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between formatOnSave and codeActionsOnSave?

Yes, I am aware of this existing question with a near-identical title: Difference between codeActionsOnSave and formatOnSave in VS Code - but its title is misleading, the question is actually focused on an issue with ESLint and Prettier.

What is the difference between formatOnSave and codeActionsOnSave?

They appear to overlap, but neither setting is marked as deprecated. Is one newer than the other? Is one preferred over the other? Are they actually documented anywhere? What happens if I use a mixture of the two? All I can find on this is outdated Stack Overflow answers referring to obscure details gleaned from old release notes.

like image 714
callum Avatar asked Dec 01 '25 22:12

callum


1 Answers

codeActionsOnSave setting lets you configure a set of Code Actions that are run when a file is saved. For example, for JavaScript, TypeScript, and other extensions that contribute an organize imports Code Action, you can enable organize imports on save by setting:

"editor.codeActionsOnSave": {
     "source.organizeImports": true
}

You can also enable or disable which Code Actions are run on save per language using a language specific setting. The following settings enable organize imports on save for TypeScript files only:

"[typescript]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
},

"[typescriptreact]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
}
like image 151
samivic Avatar answered Dec 04 '25 12:12

samivic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!