Evgeni Atanasov
Evgeni Atanasov

Reputation: 520

Visual Studio Code: Failed to apply ESLint fixes to the document

I am using Visual Studio Code 1.6.1, with latest version of ESLint extension installed and enabled. I have

"eslint.options": {
  "rules": {
    ...
  }
}

in my vs-code user settings. I was able to autofix my js files with the auto command "eslint.executeAutofix", but from maybe my last update of vs-code I am receiving the following error:

Failed to apply ESLint fixes to the document. Please consider opening an issue with steps to reproduce.

Can somebody please help me or point me in direction where I can fix this issue?

Upvotes: 9

Views: 18705

Answers (5)

Siruj
Siruj

Reputation: 460

I had a similar issue which was resolved after running npm run lint that displayed:

Configuration for rule "object-curly-spacing" is invalid:
        Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '4').

A simple mistake on my part in providing the incorrect config value, but the error only showed up in the terminal after calling the npm command. Check if your eslintrc.json has invalid rules!

Upvotes: 0

JHannes
JHannes

Reputation: 1484

I just ran into the same issue and wanted to share my solution:

For me npx eslint path/to/your/file ran just fine, but I had a custom eslint config in my settings.json that was malformed so that's why the command failed in vscode only.

I realized that when I opened the eslint output ("View" => "Output" or click on the ESLint tab in the editor footer) and there I saw some errors.

The message Please consider opening an issue with steps to reproduce. was not so helpful here, maybe Please check your ESLint output for errors. would be better.

Upvotes: 0

Eugene Ihnatsyeu
Eugene Ihnatsyeu

Reputation: 1585

Run eslint lint .\filename on your file and see what it says.

In my case it was Error: unreachable. Then I started deleting small chunks of my code and running eslint lint .\filename over and over again untill I found the exact line that caused the issue. Turns out I made a stupid mistake using ?? in js file instead of ||

Upvotes: 0

Pavel
Pavel

Reputation: 583

For anyone who bumps into the same issue. To troubleshoot, try running npx eslint path/to/your/file to see the actual eslint output.

In my case it was missing Prettier plugin:

Failed to load plugin 'prettier' declared in '.eslintrc.js » @react-native-community/eslint-config': Cannot find module 'eslint-plugin-prettier'

Upvotes: 21

Evgeni Atanasov
Evgeni Atanasov

Reputation: 520

Somehow npm install eslint --save-dev fixed the issue. Now it is working even after npm uninstall eslint --save-dev. Strange...

Upvotes: 0

Related Questions