Get eslint plugin, add this code to your settings.json

 {
  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit"
  }
 }

source

Answer from Wojciechu on Stack Overflow
🌐
DEV Community
dev.to › muratcanyuksel › quick-eslint-guide-vscode-eslint-on-save-3ik0
Quick ESLint guide + VsCode ESLint on save - DEV Community
July 11, 2021 - On VsCode, go to preferences-settings-extensions-eslint ( you can search for ESLint once in the settings and do not forget to click on Workspace because that's where we're gonna change the settings) and there, on the right top of the page, you'll ...
🌐
Aleksandr Hovhannisyan
aleksandrhovhannisyan.com › blog › eslint-format-on-save
How to Format on Save with ESlint | Aleksandr Hovhannisyan
August 22, 2024 - This creates an extensions.json file in a .vscode/ folder at the root of your project. Add the string ID for the ESLint extension that you installed: ... Commit this file so that other developers on your team receive a prompt to install the ESLint plugin if they don’t already have it. Now we can tell VS Code to auto-format our code with ESLint whenever we save a file.
🌐
Dave Ceddia
daveceddia.com › vscode-use-eslintrc
ESLint + VSCode: How to Format Your Code Using .eslintrc
The first one turns on ESLint for formatting, and the next 3 make it do the formatting when you hit save.
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 833
Extension not auto-fixing on Save · Issue #833 · microsoft/vscode-eslint
December 16, 2019 - I got the upgrade to 2.0.4 (and subsequently to 2.0.5 a little bit ago) and I'm having trouble configuring ESLint to auto-fix issues on Save. Previously we had the "eslint.autoFixOnSave" setting, but it looks like this was replaced by th...
Author   dracozombie19
🌐
DigitalOcean
digitalocean.com › community › tutorials › linting-and-formatting-with-eslint-in-vs-code
How To Lint and Format Code with ESLint in Visual Studio Code | DigitalOcean
October 17, 2024 - Now that your JavaScript project is properly set up, you can now set up ESLint. Before you set up ESLint for your project, you will first need to install ESLint: ... It’s important to include the --save-dev flag because this saves the package as a dependency for development usage only...
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
ESLint - Visual Studio Marketplace
Extension for Visual Studio Code - Integrates ESLint JavaScript into VS Code.
Find elsewhere
🌐
Aleksandr Hovhannisyan
aleksandrhovhannisyan.com › blog › format-code-on-save-vs-code-eslint
How to Format Code on Save in VS Code with ESlint | Aleksandr Hovhannisyan
August 15, 2024 - Now, just open up a file and mess it up on purpose; you should see squiggly red lines if the violation is treated as an error and orange if it’s a warning. VS Code will auto-format your code with ESLint when you save the file.
🌐
Medium
medium.com › @mani.tamilarasan › how-to-fix-eslint-stylelint-errors-upon-save-in-vs-code-1e0ed98ccb40
How to Fix ESLint & StyleLint Errors Upon Save in VS Code | by Mani Tamilarasan | Medium
May 8, 2020 - Complete the following steps to make Visual Studio Code fix any lint errors when a file is saved: Open the following file path: ~/Library/Application Support/Code/User/settings.json ... "editor.codeActionsOnSave": { "source.fixAll.eslint": true, "source.fixAll.stylelint": true},"eslint.validate": ["javascript"],"css.validate": false,"less.validate": false,"scss.validate": false,"editor.formatOnSave": false,
🌐
YouTube
youtube.com › pentacode
How to run ESLINT on save (VS Code) - YouTube
$200 DigitalOcean hosting coupon: https://m.do.co/c/dba93b1bbe11Discord: http://discord.com/invite/tBDRpfULike my videos and tutorials? Consider donating: ht...
Published   May 1, 2021
Views   8K
🌐
React-japan
react-japan.dev › en › blog › eslint-fix-on-save
Level up your workflow with ESLint fix on save - React Japan
The --max-warnings=0 flag in ESLint takes care of this automatically. The easiest and most common way to run on commit is with lint-staged via husky. This will save time by only running linters on files that have changed.
🌐
David Walsh
davidwalsh.name › eslint-vscode
How to Fix ESLint Errors Upon Save in VS Code
May 24, 2020 - By setting the `editor.codeActionsOnSave` configuration of VS Code to `source.fixAll`, eslint runs and fixeds errors on every save.
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 1538
Saving files with eslint code action is really slow · Issue #1538 · microsoft/vscode-eslint
October 17, 2022 - Type: Performance Issue when I add eslint code action on saving, saving files becomes really slow "editor.codeActionsOnSave": { "source.fixAll": true, } I ran the Bisect and found that the problem comes from eslint extension here are my ...
Author   salamaashoush
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 843
Eslint is not linting on save (with new setting in json) · Issue #843 · microsoft/vscode-eslint
December 17, 2019 - We have been using eslint heavily, but with the new update(2.0.4) our files are no longer being linted. My output dialog box keeps saying Cannot find module 'babel-eslint' and Cannot find module 'eslint-config-airbnb' if I attempt to use...
Author   JarrodMFlesch
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 1344
How to tackle: Getting code actions from ESLint · Issue #1344 · microsoft/vscode-eslint
October 1, 2021 - use the setting "eslint.codeActionsOnSave.mode": "problems". This disables ESLints behavior were it runs the validation n times until the last run didn't compute any additional fixes. If that is set to "all" which is the default, ESLint will run n (n >= 2) validation passes for that single document on every save.
Author   dbaeumer
Top answer
1 of 2
10

VSCode doesn't support chaining multiple formatters. More at this related question.

But chaining formatters isn't the answer to your problem. If you're using Prettier and ESLint properly then they do not overlap in their ruleset. You can use eslint-plugin-prettier to format the document with only ESLint and it will run Prettier as an ESLint rule. Adding eslint-config-prettier disables any ESLint rules that would conflict with Prettier.

Afterwards, running eslint --fix would apply both your ESLint and Prettier rules in a single format.

If you would like to use ESLint with other filetypes then you need to find ESLint plugins that work for those filetypes. They require installation and configuration unique to each plugin. An example is eslint-plugin-jsonc to add support for JSONC.

In package.json:

{
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^6.10.0",
    "@typescript-eslint/parser": "^6.10.0",
    "eslint": "^8.53.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.1",
    "prettier": "^3.0.3",
    "typescript": "^5.2.2"
  }
}

In .eslintrc.json:

{
  "extends": [
    "plugin:prettier/recommended" // must be last element in "extends"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [
        ".ts"
      ]
    },
  }
}

Set your Prettier rules in .prettierrc.json, for example:

{
  "printWidth": 100
}

Now eslint --fix will format the document in a single pass.

For VSCode, install both the dbaeumer.vscode-eslint and the esbenp.prettier-vscode extensions. These each require you to have the corresponding npm package installed, whether locally in your app or globally on your device. You may also need to configure VSCode so that it can find the packages, depending on how they were installed.

Then when you run Format Document With and select ESLint it will apply both your ESLint and Prettier rules with the equivalent of eslint --fix. For example, leaving a trailing space will trigger this INFO alert:

Delete `·` eslint (prettier/prettier)

Formatting the document with ESLint resolves the issue.

2 of 2
1

This bugged me ALOT as well. There are a lot of resources online about different ways. The problem is most of them are outdated, don't work, require some config adjustments, and have their own set of trade-offs.

Here was the solution I ended up going with:

I just added this to my users keybindings.json:

{
    "key": "cmd+alt+f",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
        "text": "npx prettier --write '${file}' > /dev/null 2>&1 && npx eslint_d --fix '${file}' > /dev/null 2>&1 & \u000D" // The CLI command to run "\u000D" is just the return key.
    },
    "when": "editorTextFocus"
},

That command uses eslint_d but thats just a performance enhancement. You could just as easily use eslint instead.

If you want to get it to run on save. You can try vscode-run-on-save

The benefit of this was it just works across any flavor of vscode like cursor, windsurf, etc. I don't have to muck with configs or any other setup.

Hope this helps someone else :).

🌐
GitHub
github.com › microsoft › vscode-eslint
GitHub - microsoft/vscode-eslint: VSCode extension to integrate eslint into VSCode · GitHub
Add a command ESLint: Revalidate all open files to revalidate all open files. ... added settings options to control the time budget for validation and fix on save before a warning or error is raised.
Starred by 1.9K users
Forked by 370 users
Languages   TypeScript 62.7% | Jupyter Notebook 31.1% | JavaScript 5.8%
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 600
eslint.autoFixOnSave does not trigger consistently · Issue #600 · microsoft/vscode-eslint
November 14, 2018 - As asked in #283 I set the setting eslint.server.trace to "messages" and observed that when the plugin does not work as expected this lines are not shown in the trace logs: [Trace - 3:46:33 PM] Sending request 'textDocument/willSaveWaitUntil - (2)'. [Trace - 3:46:33 PM] Received response 'textDocument/willSaveWaitUntil - (2)' in 110ms. They are outputted just before textDocument/didSave in the normal situation, but not when the plugin does not fixe on save.
Author   nicobarray
🌐
GitHub
github.com › microsoft › vscode-eslint › issues › 1856
vscode-eslint extension not working on latest version of VSCode, v1.90.0 · Issue #1856 · microsoft/vscode-eslint
June 7, 2024 - This particular project is on Yarn v4.0.2 so there is an ESLint SDK installed, hence the path in the logs above. But when saving a file, I see this pop-up at the bottom right of VSCode that seems to hang there indefinitely:
Author   D-Maher