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

eslint --print-config no longer works when given a directory #11874

Closed
francoism90 opened this issue Jun 22, 2019 · 21 comments

Comments

Projects
None yet
8 participants
@francoism90
Copy link

commented Jun 22, 2019

Tell us about your environment

  • ESLint Version: v6.0.0
  • Node Version: v11.15.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

module.exports = {
  env: {
    browser: true,
    commonjs: true,
    es6: true
  },
  extends: [
    'standard',
    'plugin:vue/recommended',
    'prettier',
    'prettier/babel',
    'prettier/standard',
    'prettier/vue'
  ],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module'
  },
  plugins: ['babel', 'prettier', 'standard', 'vue'],
  rules: { 'prettier/prettier': 'error' }
};
$ cd /home/user/www/project && yarn run eslint --print-config .

What did you expect to happen?
Printing config

What actually happened? Please include the actual, raw output from ESLint.
Looks in upper path instead of current.

Oops! Something went wrong! :(

ESLint: 6.0.0.
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:

    eslint --init

ESLint looked for configuration files in /home/user/www and its ancestors.

Project path is located at /home/user/www/project.

Are you willing to submit a pull request to fix this bug?
No, sorry.

@g-plane

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

Hey @francoism90 , thanks for the issue.

Where does your .eslintrc.js locate?

Also, can you install ESLint v5 and try it again to let us know whether it's a bug in v6 or not?

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 22, 2019

@g-plane Downgrading to Eslint v5 fixes this issue:

  "devDependencies": {
    "cross-env": "^5.2",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^5.0.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-babel": "^5.3.0",
    "eslint-plugin-import": "^2.17.3",
    "eslint-plugin-node": "^9.1.0",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-standard": "^4.0.0",
    "eslint-plugin-vue": "^5.2.2",
    "laravel-mix": "^4.0.16",
    "pug-plain-loader": "^1.0.0",
    "resolve-url-loader": "3.1.0",
    "sass-loader": "^7.1.0",
    "vue": "^2.6.10",
    "vue-template-compiler": "^2.6.10"
  }

The configuration file is located at /home/user/www/project/.eslintrc.js and I'm running the command in the same location after/prior ESLint upgrade. I tried removing node_modules, possible caches, etc.

It seems the upper directory is used instead of the project's root.

@g-plane

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

How about your package.json? Does it locate at /home/user/www or /home/user/www/project?

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 22, 2019

@g-plane /home/user/www/project - everything is the same, except the upgrade to "eslint": "^6.0.0".

@g-plane

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

It seems that I can't reproduce this on my PC (Windows 10).

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 22, 2019

@g-plane This is on Linux, path lookup may differ.

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 22, 2019

For the record, this also happens when upgrading to v6, creating a new .eslintrc.js using yarn run eslint --init and finally running yarn run eslint --print-config .

@mysticatea

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

I wonder if this is an error message confusing because eslint-plugin-vue has not supported ESLint 6 yet.

Does the error disappear after you remove vue related settings?

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 22, 2019

@mysticatea Unfortunately no:

$ cat .eslintrc.js
module.exports = {
  'env': {
    'browser': true,
    'es6': true
  },
  'extends': [
    'standard'
  ],
  'globals': {
    'Atomics': 'readonly',
    'SharedArrayBuffer': 'readonly'
  },
  'parserOptions': {
    'ecmaVersion': 2018,
    'sourceType': 'module'
  },
  'rules': {
  }
}
$ yarn run eslint --print-config .
yarn run v1.16.0
$ /home/user/www/project/node_modules/.bin/eslint --print-config .

Oops! Something went wrong! :(

ESLint: 6.0.0.
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:

    eslint --init

ESLint looked for configuration files in /home/user/www and its ancestors. If it found none, it then looked in your home directory.
@mensfeld

This comment has been minimized.

Copy link

commented Jun 22, 2019

I have a similar problem, despite having proper packages in place:

Oops! Something went wrong! :(

ESLint: 6.0.0.
ESLint couldn't find the config "airbnb" to extend from. Please check that the name of the config is correct.

If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.

@aladdin-add aladdin-add added core evaluating and removed triage labels Jun 22, 2019

@malcolmr

This comment has been minimized.

Copy link

commented Jun 22, 2019

I can reproduce on Windows here. In my case, running eslint --init will generate (e.g.) .eslintrc.json in the current directory, but eslint --print-config . still prints a similar message.

From the error message (and as shown above), it looks like eslint --print-config is starting from the parent of the specified directory: if I run eslint --print-config foo, everything seems to work (even though I don't have a directory called foo).

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

Does this issue occur when you actually lint a file, or only when using --print-config?

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

@mensfeld I think the error you're encountering might have a different cause -- feel free to open a new issue for it or stop by in the Gitter chat.

@not-an-aardvark not-an-aardvark added accepted and removed evaluating labels Jun 22, 2019

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

I can reproduce this issue as it relates to --print-config. However, as far as I can tell, linting itself is still working properly. Feel free to let me know if I've misunderstood the problem.

@not-an-aardvark not-an-aardvark added evaluating and removed accepted labels Jun 22, 2019

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Jun 22, 2019

Actually, it seems like the issue is that --print-config only works when provided with a filepath, whereas it would previously also work when provided with a directory. So eslint --print-config . doesn't work, but eslint --print-config someFile.js does work.

@mysticatea Do you think this is worth fixing? With upcoming changes to --overrides and --ext, it seems like getting the config for a directory might not make much sense conceptually anymore. On the other hand, we could just convert --print-config . to something like --print-config ./__placeholder__.js internally and it could still provide some value.

@not-an-aardvark not-an-aardvark changed the title ESLint v6 cannot find .eslintrc.js eslint --print-config no longer works when given a directory Jun 22, 2019

@mysticatea

This comment has been minimized.

Copy link
Member

commented Jun 23, 2019

I see. I think a better message is useful. If a directory path was given with --print-config, it shows "please a path to a source code" or something like, as our document says. Because configs can be different for each source code due to overrides.

@malcolmr

This comment has been minimized.

Copy link

commented Jun 23, 2019

fwiw, I think --print-config . was a fairly simple way to ask for the config that applied to an arbitrary .js file in the current directory, but if it no longer makes sense, a better error message would be nice.

In practice (and looking through github's search), I suspect most usages are coming from people using eslint-config-prettier, due to e.g. https://github.com/prettier/eslint-config-prettier#cli-helper-tool.

@francoism90

This comment has been minimized.

Copy link
Author

commented Jun 23, 2019

@not-an-aardvark This works fine:

$ yarn run eslint --fix .
yarn run v1.16.0
Done in 0.29s.

I don't know if this helps:

$ yarn run eslint --debug --print-config .
yarn run v1.16.0
$ /home/user/www/project/node_modules/.bin/eslint --debug --print-config 
  eslint:cli CLI args: [ '--debug', '--print-config', '.' ] +0ms
  eslint:ignored-paths baseDir = "/home/user/www/project" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/node_modules/*"
  eslint:ignored-paths   cooked   = "/node_modules/*" +1ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/bower_components/*"
  eslint:ignored-paths   cooked   = "/bower_components/*" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = ".*"
  eslint:ignored-paths   cooked   = ".*" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "!../"
  eslint:ignored-paths   cooked   = "!../" +0ms
  eslint:ignored-paths Looking for ignore file in /home/user/www/project +0ms
  eslint:ignored-paths Could not find ignore file in cwd +1ms
  eslint:ignored-paths baseDir = "/home/user/www/project" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/node_modules/*"
  eslint:ignored-paths   cooked   = "/node_modules/*" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/bower_components/*"
  eslint:ignored-paths   cooked   = "/bower_components/*" +0ms
  eslint:ignored-paths Looking for ignore file in /home/user/www/project +1ms
  eslint:ignored-paths Could not find ignore file in cwd +0ms
  eslint:cascading-config-array-factory Load config files for /home/user/www. +0ms
  eslint:cascading-config-array-factory No cache found: /home/user/www. +0ms
  eslint:config-array-factory Config file not found on /home/user/www +0ms
  eslint:cascading-config-array-factory No cache found: /home/user. +1ms
  eslint:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslint:cascading-config-array-factory Loading the config file of the home directory. +0ms
  eslint:config-array-factory Config file not found on /home/user +0ms
  eslint:cascading-config-array-factory Configuration was determined: ConfigArray [] on /home/user/www +0ms

Oops! Something went wrong! :(

ESLint: 6.0.0.
ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:

    eslint --init

ESLint looked for configuration files in /home/user/www and its ancestors. If it found none, it then looked in your home directory.

Thanks for taking a look, don't know if this may cause issues, I just use this command for testing the config as can been in the prettier example.

@mensfeld

This comment has been minimized.

Copy link

commented Jun 23, 2019

@not-an-aardvark it seems it's related directly to lack of support of the new es linter from the airbnb package maintainers: airbnb/javascript#2036

@mysticatea

This comment has been minimized.

Copy link
Member

commented Jun 23, 2019

Since v4.1.0, ESLint has supported glob-based configuration. So --print-config with a directory path doesn't make sense anymore. Configurations are not per directory.

And the document says requiring a file path and print the configuration for linting the given file. I think that the solution is a better error message when a directory path was given.

mysticatea added a commit that referenced this issue Jun 23, 2019

@lydell

This comment has been minimized.

Copy link

commented Jun 24, 2019

I think there might be a few usages of eslint --print-config . in the wild because of https://github.com/prettier/eslint-config-prettier/#cli-helper-tool

I need to update that section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.