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

[BUG] not working with eslint 6 #870

Closed
jimblue opened this issue Jul 9, 2019 · 41 comments
Closed

[BUG] not working with eslint 6 #870

jimblue opened this issue Jul 9, 2019 · 41 comments
Labels
bug locked Please open a new issue and fill out the template instead of commenting.

Comments

@jimblue
Copy link

jimblue commented Jul 9, 2019

Hi,

When using the option eslint-integration, Prettier is not working and output the following error:

ENOENT/home/dev/frontend/webpacker/app/index.js:: no such file or directory, open '/home/dev/projects/frontend/node_modules/eslint/lib/linter.js'

I've check in my node_modules and effectively, linter.js doesn't exist.

It was previously working with eslint version 5 because linter.js did exist at this path here.

But in eslint version 6, linter.js has been moved in a subfolder here.

That's why it's actually broken.
So basically all you have to do is to modify the require:

from:

require /node_modules/eslint/lib/linter.js

to:

require /node_modules/eslint/lib/linter/index.js

Cheers

@jakeleventhal
Copy link

Need this ASAP!

@chengjia080787
Copy link

any luck on this? it's a critical issue to be honest

@mbalaam
Copy link

mbalaam commented Jul 22, 2019

I’ve ended up removing the extension and I am using https://github.com/prettier/eslint-plugin-prettier instead.

@tcodes0
Copy link

tcodes0 commented Jul 30, 2019

running "prettier.eslintIntegration": false as a work around

@asbjornh
Copy link

asbjornh commented Aug 7, 2019

to:

require /node_modules/eslint/lib/linter/index.js

Maybe change to require('node_modules/eslint/lib/linter') instead? Node's module resolution would then check both linter.js and linter/index.js. If the import looked like that in the first place we wouldn't have an issue now 😃

@asbjornh
Copy link

asbjornh commented Aug 8, 2019

@jimblue Where is that require call coming from? I can't see that this package imports eslint anywhere in the source and eslint isn't listed in package.json either. I tried grep'ing the plugin folder and nothing really looks suspicious.

In ~/.vscode/extensions/esbenp.prettier-vscode-1.9.0:

$ grep -r "/linter" .
./node_modules/tslint/lib/test.js:var linter_1 = require("./linter");
./node_modules/tslint/lib/runner.js:var linter_1 = require("./linter");
./node_modules/tslint/lib/index.js:tslib_1.__exportStar(require("./linter"), exports);
./node_modules/tslint/lib/index.d.ts:export * from "./linter";
./node_modules/tslint/lib/tslintCli.js:var linter_1 = require("./linter");
./node_modules/prettier-tslint/dist/format.js:  // Adapted from: https://github.com/palantir/tslint/blob/5.12.0/src/linter.ts
./node_modules/eslint/lib/config/autoconfig.js:    Linter = require("../linter"),
./node_modules/eslint/lib/testers/rule-tester.js:    Linter = require("../linter"),
./node_modules/eslint/lib/api.js:const Linter = require("./linter");
./node_modules/eslint/lib/cli-engine.js:    Linter = require("./linter"),

@asbjornh
Copy link

asbjornh commented Aug 9, 2019

I tried creating a fresh project to reproduce, and I'm now getting a different error message:

Failed to load plugin 'prettier' declared in 'CLIOptions'<project-path>/index.js:: Cannot find module 'eslint-plugin-prettier'
Require stack:
- /__placeholder__.js

eslint-plugin-prettier is most definitely installed. For anyone interested in debugging this, here is a setup for reproducing this:

  "dependencies": {
    "eslint": "^6.1.0",
    "eslint-config-prettier": "^6.0.0",
    "eslint-plugin-prettier": "^3.1.0",
    "prettier": "^1.18.2"
  }

eslintrc:

{
  "plugins": ["prettier"],
  "extends": ["prettier"],
  "rules": {
    "prettier/prettier": ["warn"]
  }
}

Running with prettier.eslintIntegration: true and selecting Format Document With from the command palette in an empty js file should result in the above error message.

@ntotten ntotten added the bug label Aug 9, 2019
@ntotten ntotten modified the milestones: 1.9.0, 1.10.0 Aug 9, 2019
@asbjornh
Copy link

Oh, this seems to be caused by a known issue with prettier-eslint (prettier/prettier-eslint#222). I guess we'll have to wait for them to fix that first :)

@ntotten
Copy link
Member

ntotten commented Aug 12, 2019

As mentioned above, there is an upstream dependancy on the prettier eslint module. It is not yet compatible with eslint 6. see: prettier/prettier-eslint#222

@ntotten
Copy link
Member

ntotten commented Aug 12, 2019

After investigating these issues we are considering removing support for linters in version 2.0.0. Instead of incorporating the linters into this extension the proposal is to use the ESLint or TSLint extensions along with this extension. Please let us know what you think by commenting on #901.

By using the official extensions issues like these will be centralized and fixed more quickly as the authors of those extensions are focusing solely on those linters.

@ntotten
Copy link
Member

ntotten commented Aug 25, 2019

Here is a good article explaining the type of setup that is recommended going forward: https://dorshinar.me/linting-your-react+typescript-project-with-eslint-and-prettier

@ntotten
Copy link
Member

ntotten commented Aug 25, 2019

More discussion also in #922

@YuriScarbaci
Copy link

Until this is fixed in the extension if anyone is relying on the eslint-vscode extension and wishes to setup a keybinding to "format" (well, fixing with eslint, but in most cases it's formatting anyway) you could set a keybindg in your vscode with "shift+alt+f" (or whatever you wish) listening to eslint.executeAutofix

for more info about this refeer to https://github.com/Microsoft/vscode-eslint/issues/70

@ntotten ntotten mentioned this issue Oct 20, 2019
13 tasks
@mihaiwww
Copy link

mihaiwww commented Oct 26, 2019

How I've sorted it after having super huge frustrations with Prettier stopping working.

VS Code -> View -> Command Palette, type: Format Document With, then Configure Default Formatter... and then choose Prettier - Code formatter.

This sorted the problem for me magically. It looks that VS Code had other options for formatting not only Prettier but did not show any error or notification so you can choose from.

I hope it helps others too!

@Salles-FA
Copy link

3.6.0 and 3.7.0 are ok! But it seems like the same problem is back in 3.8.0 today. Or even a similar problem.

Can you guys take a look?

Output with 3.6.0 and 3.7.0:

[INFO - 2:02:11 PM] Prettier Options:
{
  "arrowParens": "avoid",
  "bracketSpacing": true,
  "endOfLine": "auto",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": true,
  "printWidth": 120,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "none",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "c:\\somefile.ts",
  "parser": "typescript"
}

Output with 3.8.0:

[INFO - 1:54:38 PM] Prettier Options:
    {
      "filepath": "c:\\somefime.ts",
      "parser": "typescript",
      "useTabs": false,
      "tabWidth": 2
    }

@Salles-FA
Copy link

Same problem with 3.11.0 here.

@ntotten
Copy link
Member

ntotten commented Dec 19, 2019

ESLint 6 is NOT supported by this extension at the moment. I won’t spend time on this until the upstream libraries officially support ESLint 6. Once prettier/prettier-eslint#222 is resolved I will work on this bug.

@uniquejava
Copy link

uniquejava commented Jan 3, 2020

Auto format on save suddenly NOT WORK in recent days, I have to format document with keyboard :(
Uninstall vscode-eslint fixed auto format on save issue!

@kebot
Copy link

kebot commented Jan 6, 2020

vscode-eslint recently suggests using editor.codeActionsOnSave, and I found it doesn't work well with editor.formatOnSave because it runs eslint fix first then prettier. What I want is prettier then eslint fix.

Then I add editor.action.formatDocument to codeActionsOnSave and disable formatOnSave, everything works fine for me now.

This is my current config, tested on MacOS with:

VSCode: 1.41.1
prettier-vscode: 3.18.0
vscode-eslint: 2.0.11

{
  "[javascriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.formatOnSave": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "editor.action.formatDocument": true
  }
}

@JoelAzevedo
Copy link

How I've sorted it after having super huge frustrations with Prettier stopping working.

VS Code -> View -> Command Palette, type: Format Document With, then Configure Default Formatter... and then choose Prettier - Code formatter.

This sorted the problem for me magically. It looks that VS Code had other options for formatting not only Prettier but did not show any error or notification so you can choose from.

I hope it helps others too!

I can't thank you enough. I was going almost crazy with the settings. It actually magically solved it.

Thank you x100

@ntotten
Copy link
Member

ntotten commented Feb 4, 2020

It seems like prettier-eslint is mostly a dead project so it is unlikely this will ever get fixed. I would suggest switching to the recommended approach of integrating ESLint and Prettier

@rohit-gohri
Copy link

rohit-gohri commented Apr 29, 2020

I couldn't get @kebot's workaround to work on the latest extension and vscode versions. So I published a small extension to run 'Format Document' as a codeAction:

https://github.com/rohit-gohri/vscode-format-code-action/

Along with the latest VS Code update, which allows setting order of codeActionsOnSave, this removes the need for prettier-eslint to specify the order of commands in VS Code. We can use the prettier-vscode and vscode-eslint extensions separately and just define the order in vscode settings.

Example here: #1277 (comment)

@zmeyc

This comment has been minimized.

@ntotten
Copy link
Member

ntotten commented Jun 24, 2020

Linting integration has been removed from this extension. If you want to run prettier and ESlint together you should use the ESLint extension instead. See: https://github.com/prettier/prettier-vscode#linter-integration

@prettier prettier locked as resolved and limited conversation to collaborators Jun 24, 2020
@ntotten ntotten added the locked Please open a new issue and fill out the template instead of commenting. label Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests