Sub topic 12
Editor Integration and Format on Save
This chapter assumes you already have ESLint configured with eslint.config.js, Prettier configured with .prettierrc, and eslint-config-prettier installed so the two tools do not conflict. The examples use Visual Studio Code. Other editors such as WebStorm, Neovim, and Zed offer similar settings under different names.
Running the tools from the terminal works, but the feedback comes late. When the editor runs them, ESLint problems appear as squiggles while you type, and Prettier formats each file when you save it.
The Two Extensions
Install these two VS Code extensions:
- ESLint (
dbaeumer.vscode-eslint) runs the ESLint package installed in your project and shows its diagnostics inline. It also exposes ESLint's autofixes as code actions. - Prettier (
esbenp.prettier-vscode) registers Prettier as a formatter. It uses the project's localprettierpackage and.prettierrcwhen they exist.
Both extensions read your project's configuration files. Your editor therefore applies the same rules as your npm scripts and CI.
Workspace Settings
Put the settings in .vscode/settings.json and commit the file, so every contributor gets the same behavior:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}source.fixAll.eslint applies every available ESLint autofix when you save manually. formatOnSave then runs Prettier. VS Code runs code actions before the formatter, so Prettier always gets the last word on layout.
To prompt teammates to install the extensions, add .vscode/extensions.json:
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}Common Errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Save does nothing to formatting | Another formatter is the default for that language | Set `"[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }` |
| Editor and CI disagree on formatting | The extension fell back to a bundled Prettier version | Install `prettier` as a devDependency so the extension uses the project's copy |
| No ESLint squiggles | ESLint is not installed locally, or the config file failed to load | Check the ESLint output panel (View → Output → ESLint) |
| Code jumps back and forth on save | A formatting rule in ESLint conflicts with Prettier | Make sure `eslint-config-prettier` is the last config entry |
Exercise
A teammate reports that saving a file fixes eqeqeq violations but leaves long lines unwrapped. Their .vscode/settings.json contains only editor.codeActionsOnSave with source.fixAll.eslint. What is missing, and why does the ESLint part still work?
Show answer
The file is missing "editor.formatOnSave": true and "editor.defaultFormatter": "esbenp.prettier-vscode". ESLint fixes still run because they are code actions, and VS Code triggers code actions separately from formatting. Line wrapping is Prettier's job, and Prettier only runs when format on save is enabled.
Exercise
Why should .vscode/settings.json be committed to the repository instead of each developer configuring their user settings?
Show answer
Workspace settings give every contributor the same save behavior and override conflicting user-level formatters. That reduces formatting churn in diffs.