Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tackle: Getting code actions from ESLint #1344

Open
dbaeumer opened this issue Oct 1, 2021 · 4 comments
Open

How to tackle: Getting code actions from ESLint #1344

dbaeumer opened this issue Oct 1, 2021 · 4 comments
Labels
Milestone

Comments

@dbaeumer
Copy link
Member

dbaeumer commented Oct 1, 2021

The cause of seeing that dialog can have many reasons. They are in almost all cases not related to the ESLint extension itself.

Typically reasons are:

  • one of the eslint plugins is slow
  • VS Code's extension host is busy which is usually caused by an extension different than ESLint

Finding the reason

Before you file an issue please follow the following steps to narrow down the problem:

  • disable all other extensions except ESLint. If the problem doesn't reproduce anymore use VS Codes extension bisect tool to identify the extension that causes the problem.
  • run eslint in the terminal with the --fix option on the same file you get the slow saving dialog on. If that runs slow it will reveal the same behavior in the ESLint extension.
  • open VS Code's process explorer tool (Help -> Open Process Explorer) and look for the extensionHost process. If that has high CPU load than it is very likely caused by an extension. Again use the bisect tool to identify the problematic extension.
  • eslint itself or one of its plugin is slow: this can best be figured out by running the extension with "eslint.debug": true and inspecting the timings in the ESLint output channel. In these scenarios eslint in the terminal is slow as well.
  • an eslint plugin uses deasync to make async calls sync. This can lead to complete hangs of the VM especially when used in a Electron node runtime (which VS Code does). A workaround could be to set the node runtime used for ESLint to a locally installed node version using the eslint.runtime setting.

Some tips how to make the dialog less likely

  • 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. The side effect of using problems however is that not all fixable problems might be fixed.
  • Use the new setting (only available in > 2.2.0) eslint.codeActionsOnSave.rules setting to explicitly specify rules that should be evaluated on save. This helps to exclude expensive rules that might not even produce fixes.
  • Decouple saving in VS Code from running code actions on save. There are two ways to do so:
    • enabled auto save again in VS Code (this will automatically save the file but not run code actions on save) and trigger code action on save by pressing Ctrl+S (which in this setup will not save the file).
    • disable code action on save and either use Format Document (Shift+ALt+F) (eslint needs to be configure to format the document) or the separate ESLint: Fix all autofixable problems command (which can be bound to a short cut).

Filing an issue

If you file an issue for this please open a separate issue with steps on how to reproduce it. Please don't add to existing issues since the cause of the hang is very likely unique.

@whenmoon
Copy link

"eslint.codeActionsOnSave.mode" is deprecated, please use "editor.codeActionsOnSave": { "source.fixAll.eslint": true }

@jkulak
Copy link

jkulak commented Oct 30, 2022

I recently switched to Pre-Release versions of Python, Pylance, isort VSCode extensions and only then started seeing this notification. At the same time at least one of those extensions required a restart. Restarting VSCode solves this issue for me.

@abubakarasifmughal
Copy link

I just removed this from settings.json, didn't hurt at all

 "editor.codeActionsOnSave": {
    "source.fixAll": "always",
    "source.organizeImports": "always",
    "editor.codeActionsOnSave": { "source.fixAll.eslint": true }
},

@MarArMar
Copy link

MarArMar commented May 21, 2024

To help with setting the "eslint.runtime" setting:

You can set it to the output of

which node

To install additional specific runtimes, you can use nvm

So the setting should look like

    "eslint.runtime": "/home/user/.nvm/versions/node/v20.13.1/bin/node" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants