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

Not working properly width eslint 6 #222

Closed
nashaofu opened this issue Jul 11, 2019 · 13 comments · Fixed by #236
Closed

Not working properly width eslint 6 #222

nashaofu opened this issue Jul 11, 2019 · 13 comments · Fixed by #236
Labels

Comments

@nashaofu
Copy link

nashaofu commented Jul 11, 2019

Versions:

  • prettier-eslint 9.0.0:
  • node 10.15.3:
  • npm (or yarn) version: 6.10.0

Have you followed the debugging tips?

Yes

Relevant code or config

const eslintOptions = {};
if (filePath) {
eslintOptions.cwd = path.dirname(filePath);
}
logger.trace(
oneLine`
creating ESLint CLI Engine to get the config for
"${filePath || process.cwd()}"
`
);
const cliEngine = getESLintCLIEngine(eslintPath, eslintOptions);
try {
logger.debug(`getting eslint config for file at "${filePath}"`);
const config = cliEngine.getConfigForFile(filePath);
logger.trace(
`eslint config for "${filePath}" received`,
prettyFormat(config)
);
return config;

  const eslintOptions = {};
  if (filePath) {
    eslintOptions.cwd = path.dirname(filePath);
  }
  logger.trace(
    oneLine`
      creating ESLint CLI Engine to get the config for
      "${filePath || process.cwd()}"
    `
  );
  const cliEngine = getESLintCLIEngine(eslintPath, eslintOptions);
  try {
    logger.debug(`getting eslint config for file at "${filePath}"`);
    const config = cliEngine.getConfigForFile(filePath);
+   config.cwd = eslintOptions.cwd
    logger.trace(
      `eslint config for "${filePath}" received`,
      prettyFormat(config)
    );
    return config;

What I did:

Support eslint 6

What happened:
when I set "prettier.eslintIntegration": true
then the error happend in VSCode

Failed to load plugin 'standard' declared in 'CLIOptions'/Users/nashaofu/edc/web/src/c.js:: Cannot find module 'eslint-plugin-standard'
Require stack:
- __placeholder__.js

My eslint configuration is as follows:

module.exports = {
  root: true,
  parser: 'babel-eslint',
  env: {
    es6: true,
    node: true,
    commonjs: true
  },
  extends: ['standard']
}

Problem description:

The CWD of the process pointed incorrectly

Suggested solution:
details prettier/prettier-vscode#869

@joshuadiablito
Copy link

this is causing me issues too - any help resolving would be great!

@zimme
Copy link
Member

zimme commented Jul 17, 2019

We just recently added support for eslint 5 so prettier-eslint might not work with eslint 6 as it hasn't been tested by us and depends on eslint 5. Will accept a PR for eslint 6 support otherwise I'll try and get to it in a couple of weeks as I'm on vacation currently.

@phts
Copy link

phts commented Jul 19, 2019

@zimme @nashaofu I found related one more issue related to eslint 6 and CWD.

Minimal reproducible repo: https://github.com/phts/prettier-eslint-overrides-bug

TL;DR:

Issue with overrides.

When I set override with explicit file path, e.g. src/myFile.js - eslint cannot match config to this file, and eslint will be just skipped by prettier-eslint --write **/*.js.

When override contains ** - then everything works fine.

And if I remove line eslintOptions.cwd = path.dirname(filePath); - all cases above work fine.

@nashaofu
Copy link
Author

@phts If I remove line eslintOptions.cwd = path.dirname(filePath);, it doesn't seem to use eslint, it just uses prettier.

@mciesin
Copy link

mciesin commented Aug 6, 2019

@nashaofu could you please make a pull request with your change :)?

@zimme please look into it, we really need this fix.

The reason for the problem (also reported in microsoft/vscode-eslint#696 and prettier/prettier-atom#505) is setting the cwd option as the path for resolving plugins in this line and trying to resolve plugins here which results in an error if cwd isn't set correctly.

@kylemh
Copy link
Collaborator

kylemh commented Aug 19, 2019

Would appreciate some eyes on #236 (not just from this project's maintainers). I know this problem is affecting a lot of people who use VS Code and enjoy using Prettier format on save in projects that have an ESLint integration.

Removing eslintOptions.cwd = path.dirname(filePath); doesn't feel like a valid option.

@ShinobiWPS
Copy link

Any news on this?

@kylemh
Copy link
Collaborator

kylemh commented Sep 24, 2019

See Open PR for news

@kylemh
Copy link
Collaborator

kylemh commented Oct 17, 2019

I don't want to ping people with a new comment, but wow comments like the one below are not helpful. If it's such an emergency for you, feel free to fork the repo and publish the lib under your own NPM org

@agusterodin
Copy link

When open source fails

@Rulexec
Copy link

Rulexec commented Feb 13, 2020

Fixed issue by adding cwd: __dirname to my .eslintrc.js, it works (since prettier-eslint pass eslintOptions to new CLIEngine, which accepts cwd) and then all works correctly.

But feels like a hack (and eslint complains about unknown property), prettier-eslint should add cwd by itself. Easiest way to do it like this:

 function createEslintFix(eslintConfig, eslintPath) {
        return function eslintFix(text, filePath) {
+               const cwd = path.dirname(filePath);
+
                const cliEngine = (0, _utils.getESLintCLIEngine)(
                        eslintPath,
-                       eslintConfig,
+                       Object.assign(Object.create(null), eslintConfig, { cwd }),
                );

But not sure, that it is not a hack too.

Rulexec pushed a commit to Rulexec/prettier-eslint that referenced this issue Feb 13, 2020
@swernerx
Copy link

swernerx commented Apr 29, 2020

Alternatively you might want to check out: https://www.npmjs.com/package/@effective/prettier comes together with a brand new extension for VSCode: https://marketplace.visualstudio.com/items?itemName=sebastian-software.effective-prettier-vscode - hopefully this fixes the issues for some.

@zimme
Copy link
Member

zimme commented May 21, 2020

🎉 This issue has been resolved in version 10.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

10 participants