webpack-contrib / eslint-loader

[DEPRECATED] A ESlint loader for webpack
MIT License
1.06k stars 121 forks source link

Missing plugin referenced by .eslintrc file in ignored node_modules folder causes warning #332

Closed akloeber closed 4 years ago

akloeber commented 4 years ago

Expected Behavior

Plugins referenced by .eslintrc file that resides in folder ignored via .eslintignore (like node_modules) should not cause any warnings. The config should be completely ignored because it is not required for linting as the associated files are ignored.

Actual Behavior

If there is a .eslintrc file somewhere in a folder ignored via .eslintignore (e.g. node_modules) and that config references a plugin which is not installed resp. needed in the outer project the following warning is raised:

╰─ yarn build
yarn run v1.22.4
$ webpack
Hash: f2c5a91af79cb8afda15
Version: webpack 4.43.0
Time: 7131ms
Built at: 2020-06-15 10:11:13 PM
         Asset      Size  Chunks             Chunk Names
main.bundle.js  15.4 KiB       0  [emitted]  main
Entrypoint main = main.bundle.js
[7] ./src/main.ts + 1 modules 210 bytes {0} [built]
    | ./src/main.ts 161 bytes [built]
    | ./extern/bar.ts 44 bytes [built]
    + 7 hidden modules

WARNING in ./node_modules/react-plotly.js/factory.js
Module Warning (from ./node_modules/eslint-loader/dist/cjs.js):
Failed to load plugin 'react' declared in 'node_modules/react-plotly.js/.eslintrc': Cannot find module 'eslint-plugin-react'
Require stack:
- /Users/aske/Repos/eslint-loader-ignore-bug/node_modules/react-plotly.js/__placeholder__.js
Referenced from: /Users/aske/Repos/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc
 @ ./src/main.ts 2:0-60 4:19-40
✨  Done in 9.94s.

Code

Repo to reproduce this bug can be found at https://github.com/akloeber/eslint-loader-ignore-bug. In this case node_modules/react-plotly.js/.eslintrc references plugin eslint-plugin-react which is not installed by the outer project.

How Do We Reproduce?

Run yarn build or webpack directly.

closingin commented 4 years ago

Hey there. I encounter the same problem, but I have a little bit more information to share.

Actually everything works normally, as long as you run eslint-loader with eslint@6.6.0. This error starts appearing when you update eslint past 6.6.0 (I tried with 6.7.0, 6.8.0, 7.0.0, and 7.4.0 versions).

I also tried to downgrade eslint-loader just in case, but all the releases from 3.0.2 to 4.0.2 (I didn't go below that) display the same error. I do think the problem lies in eslint-loader though, but you'll surely have to check the (huge) changelog of eslint@6.7.0 to find why.

closingin commented 4 years ago

Alright after investigation, the problem comes from eslint. They introduced a new way to handle ignored paths in this commit, which tries to load the eslint config of the file it's working on (don't ask me why, idk, there must be a reason).

The thing is, using CLIEngine is deprecated, so it's hard to tell if it's a real bug on eslint's side or not. I didn't have the time to investigate much longer.

Here's the debug from eslint:

  eslint:cascading-config-array-factory Load config files for /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js. +72ms
  eslint:cascading-config-array-factory No cache found: /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js. +0ms
  eslint:config-array-factory Loading legacy config file: /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc +72ms
  eslint:config-array-factory Config file found: /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc +3ms
  eslint:config-array-factory Loading {extends:"eslint:recommended"} relative to /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc +0ms
  eslint:config-array-factory Loading JS config file: /home/closingin/eslint/conf/eslint-recommended.js +0ms
  eslint:config-array-factory Loading {extends:"plugin:react/recommended"} relative to /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc +1ms
  eslint:config-array-factory Loading plugin "react" from /home/closingin/eslint-loader-ignore-bug/node_modules/react-plotly.js/.eslintrc +0ms
  eslint:config-array-factory Failed to load plugin 'react' declared in 'node_modules/react-plotly.js/.eslintrc'. +0ms
ricardogobbosouza commented 4 years ago

HI @closingin, @akloeber Please use eslint-webpack-plugin. eslint-loader will be deprecated.

ricardogobbosouza commented 4 years ago

related #328