webpack-contrib / eslint-webpack-plugin

A ESLint plugin for webpack
MIT License
255 stars 49 forks source link

ESLintPlugin not working consistently with cache.type = 'filesystem' #130

Closed durad closed 1 year ago

durad commented 2 years ago

Bug report

Actual Behavior

With webpack cache turned on and set to 'filesystem' ESLintPlugin reports errors only after first build. If files are unchanged and build is started again ESLintPlugin will not report any errors/warnings.

Expected Behavior

ESLintPlugin should always report same errors/warnings for same input files consistently regardless of the webpack cache.

How Do We Reproduce?

Minimal repo: https://github.com/durad/webpack-eslint-caching-issue

Clone, run yarn install and then run yarn build twice. Warning will be shown only the first time.

Please paste the results of npx webpack-cli info here, and mention other relevant information

~/test/node-14-webpack-eslint * master$ yarn build
yarn run v1.22.10
$ webpack --progress --config=webpack.config.js
asset main.js 28 bytes [compared for emit] [minimized] (name: main)
./src/index.js 66 bytes [built] [code generated]

WARNING in 
/Users/dusan/test/node-14-webpack-eslint/src/index.js
  2:1  warning  Unexpected var, use let or const instead  no-var

✖ 1 problem (0 errors, 1 warning)

webpack 5.64.3 compiled with 1 warning in 358 ms
✨  Done in 0.95s.
~/test/node-14-webpack-eslint * master$ 
~/test/node-14-webpack-eslint * master$ 
~/test/node-14-webpack-eslint * master$ 
~/test/node-14-webpack-eslint * master$ yarn build
yarn run v1.22.10
$ webpack --progress --config=webpack.config.js
asset main.js 28 bytes [compared for emit] [minimized] (name: main)
cached modules 66 bytes [cached] 1 module
webpack 5.64.3 compiled successfully in 209 ms
✨  Done in 0.80s.
~/test/node-14-webpack-eslint * master$ 
~/test/node-14-webpack-eslint * master$ 
~/test/node-14-webpack-eslint * master$ 

Same happens with both development and production mode.

alexander-akait commented 2 years ago

@ricardogobbosouza we should save our warnins/errors in cache and restore it for cached files/modules

durad commented 2 years ago

Is there any progress with this issue?

ricardogobbosouza commented 2 years ago

@alexander-akait Do you have any webpack cache api documentation?

alexander-akait commented 2 years ago

oh, don't see, let's open an issue in webpack docs site, anyway it is easy, here simple example https://github.com/webpack-contrib/terser-webpack-plugin/blob/master/src/index.js#L334

asset - > getLazyHashedEtag (hash) -> getItemCache (get cached stuff associated with name and hash, because one file (name) can have many cached files with different hashes, for example own file and source maps) -> getPromise (get cached file) -> storePromise (store file in cache)

alexander-akait commented 2 years ago

In your case you need store module (resourcePath maybe?) and associated errors/warnings

ricardogobbosouza commented 2 years ago

Thanks, i will analyze

kowsen commented 2 years ago

Any update on this or ideas for a workaround? This is blocking us from moving to Webpack v5 and we aren't able to come up with a way around it.

Edit: Came up with a gross workaround - if you force ESLintPlugin to run for all files (ignoring the webpack cache) and enable its built in caching, you can get similar build speed without losing the initial lints:

class ESLintPluginNoCache extends ESLintPlugin {
    async run(compiler, ...args) {
        if (!compiler.hooks.compilation.taps.find(({ name }) => name === ESLINT_PLUGIN_NOCACHE)) {
            compiler.hooks.compilation.tap(ESLINT_PLUGIN_NOCACHE, (compilation) => {
                compilation.hooks.succeedModule.intercept({
                    register: (tapInfo) => {
                        if (tapInfo.name === this.key) {
                            compilation.hooks.stillValidModule.tap(this.key, tapInfo.fn);
                        }
                        return tapInfo;
                    }
                });
            });
        }

        return super.run(compiler, ...args);
    }
}

Sadly this setup really chugs if you enable threads and relies so much on ESLintPlugin's internals that it could easily be broken by an update, but it seems to be working well enough for now.

ricardogobbosouza commented 2 years ago

Hi @kowsen I will look into it soon

instagibb commented 1 year ago

Any progress on this one?

wz57c commented 1 year ago

Has the problem been solved

SuceV587 commented 1 year ago

Any chage!