Fixing VS Code's Format on Save That Silently Uses the Wrong Formatter When Multiple Extensions Register for the Same Language
Format on Save runs every time a file is saved, but the output doesn't match what Prettier or ESLint would produce — quotes flip, semicolons appear or vanish, imports get reordered differently than expected. Nothing is actually broken; a different extension than the one intended is simply winning the competition for which formatter VS Code hands the file to.
The Problem
A workspace has "editor.formatOnSave": true enabled, and saving a file does trigger formatting — something visibly happens every time. But the result doesn't match the project's actual style guide: a Prettier config specifying single quotes and no semicolons gets ignored in favor of double quotes and semicolons, or an import order that an organize-imports extension is supposed to enforce comes out differently each time depending on which file was saved. Running the formatter manually, or from the command line, produces the correct output every time — only the automatic on-save formatting is wrong.
Why It Happens
More than one installed extension can register itself as a formatter for the same language, and VS Code has to pick exactly one of them to actually run
It's entirely normal for a workspace to have several extensions simultaneously capable of formatting the same file type — a dedicated Prettier extension, ESLint's own formatting capability, a language-specific extension like one for Vue or Svelte that bundles its own formatter, and sometimes a built-in language server that offers basic formatting too. VS Code's formatting command needs a single formatter to actually invoke, so when more than one extension has registered for a given language, something has to break the tie — and that selection doesn't always match the one the project actually intends to use.
Without an explicit default formatter set, VS Code's tie-breaking order isn't something a developer can predict by glancing at the installed extensions list
When no default is configured, VS Code resolves the conflict using its own internal priority rules, which can depend on extension activation order, how recently an extension was installed or updated, or which one most recently handled a format request in that session. This produces behavior that can genuinely differ between two machines with the identical extension list installed, or even between two sessions on the same machine — making it look like a flaky, intermittent bug rather than a deterministic configuration gap.
A workspace-level default formatter setting only applies to the language it's scoped to, so a project using several languages needs one per language, not one global setting
Setting editor.defaultFormatter at the top level of settings.json applies a single formatter choice across every language VS Code formats, which is rarely correct for a real project — a Prettier extension is usually right for JavaScript, TypeScript, and CSS, but a dedicated language extension is usually the better and only fully correct choice for something like Python or Go. A single global default either silently fails to apply for languages where that formatter doesn't support the syntax, or actively overrides a more specialized formatter that would have produced better results.
The Fix
1. Set an explicit default formatter scoped per language, not one global default
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
Scoping editor.defaultFormatter inside a language-specific block, using the [languageId] syntax, removes the ambiguity entirely for that language — VS Code no longer has to break a tie between competing extensions, because exactly one has been explicitly named as the formatter for that file type.
2. Check which extensions are actually registered as formatters for a given language before assuming which one is active
Command Palette -> "Format Document With..." -> this
shows every extension currently registered as a capable
formatter for the file's language, with the current
default (if any) marked -> compare this list against
what's actually installed and enabled
This command surfaces the real competing candidates directly, rather than guessing from the extensions list which ones might register as formatters. It's the fastest way to confirm whether an unexpected extension — one installed for an unrelated reason, like a broader language-support bundle — is quietly also offering itself as a formatter for a language it wasn't specifically installed to format.
3. Disable formatting capability on an extension that shouldn't be competing for a language at all, rather than fighting it with priority settings
{
// Some extensions expose a setting to opt out of
// acting as a formatter while keeping their other
// features (linting, IntelliSense, etc.) active:
"someExtension.enableFormatting": false
}
When an extension is installed purely for linting, IntelliSense, or syntax support but happens to also register as a formatter, the cleanest fix is turning off that specific capability if the extension exposes a setting for it — removing it from the competition entirely rather than relying on a default formatter setting to always correctly outrank it.
4. Commit the formatter settings to the workspace's .vscode/settings.json rather than leaving them in user-level settings
.vscode/settings.json (checked into the repo) overrides
user settings for everyone who opens the project folder,
removing per-developer drift in which formatter actually
runs on save.
A default formatter set only in personal, user-level settings works on one developer's machine but leaves everyone else on the team exposed to the same unpredictable tie-breaking. Committing the language-scoped formatter settings into the workspace's own .vscode/settings.json makes the correct formatter the default for anyone who opens the repository, not just the one person who happened to configure it locally.
Why This Works
Scoping editor.defaultFormatter per language removes the need for VS Code to resolve a tie at all — there's no competition between extensions once exactly one has been explicitly named for that language, so the earlier internal priority rules never get a chance to run. Checking the actual list of registered formatters via "Format Document With..." replaces guesswork about which extensions are even in contention with a direct answer, and committing the setting to the workspace rather than personal settings turns a single developer's fix into one that holds for the whole team.
Conclusion
Format on Save producing output that doesn't match a project's intended style almost never means the formatter itself is misconfigured — it usually means more than one extension is capable of formatting the same language, and VS Code's unscoped, unpredictable tie-breaking is picking a different one than the project intends on any given save. Setting an explicit, language-scoped editor.defaultFormatter, confirming the actual list of competing formatters through "Format Document With...", and committing that setting to the workspace rather than personal preferences turns an inconsistent, hard-to-reproduce formatting bug into a deterministic one that behaves the same for every developer on the project.
