webpack-contrib / eslint-webpack-plugin

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

Linting unlinked files on change #18

Closed KevinGhadyani-minted closed 3 years ago

KevinGhadyani-minted commented 4 years ago

Expected Behavior

This only runs on changed files like eslint-loader did.

Actual Behavior

This runs on all files in the context and matching the extensions of the files on your drive.

Code

webpack.config.js

const webpackConfig = {
  // Shouldn't matter what other configurations exist.
  // ...
  entry: 'src1/someFile1.js',
  plugins: [
    new ESLintWebpackPlugin({
      context: 'src1',
      extensions: ['.js'],
      fix: true,
    }),
    new ESLintWebpackPlugin({
      context: 'src2',
      extensions: ['.js'],
      fix: true,
    }),
  ],
  // ...
}

eslintrc.js

const eslintConfig = {
  rules: {
    semi: 'error',
  }
}

src1/someFile1.js

const someCode = Function.prototype;

someCode();

src2/someFile2.js

const someOtherCode = Function.prototype;

someOtherCode();

How Do We Reproduce?

  1. Put those files in the correct folder structure.
  2. Make a change in someFile2.js that should normally trigger an ESLint auto-fix (like removing a semi-colon) and save. This won't cause anything to trigger from Webpack because it's not being imported in an entrypoint.
  3. Make a change in someFile1.js and someFile2.js will be ESLint auto-fixed.

This also occurs when starting Webpack as well as on-change. For instance, if I ran this to make a production build, it would still lint all changed files; even ones not included in an entrypoint.

When using the now-deprecated eslint-loader, this behavior only worked on files either included in the rule or part of an entrypoint. Sadly, eslint-webpack-plugin globally re-runs on all modified files when a change comes through on files that are imported from an entrypoint.

Either, it should only update files watched by an entrypoint or it should run on-file-change for any valid files in its context. It should not do both.

ricardogobbosouza commented 3 years ago

Hi @KevinGhadyani-minted Try v2.2.0

ricardogobbosouza commented 3 years ago

If the problem persists using a v2.3.0 version, reopen this

KevinGhadyani-minted commented 3 years ago

Just to be clear, is the fix included in the lintDirtyModulesOnly prop or is it now part of standard operation?

jsg2021 commented 3 years ago

This now only runs on the import graph generated by webpack. All that lintDirtyModulesOnly does is skip linting on the initial build. Only files altered that trigger a rebuild will be linted on subsequent runs.