GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 78 forks source link

ESLint errors for code injected by Babel #95

Closed jcestibariz closed 3 years ago

jcestibariz commented 3 years ago

I'm using Babel with preset-env for IE support (sad, I know), and I'm getting these errors:

/.../TestWorker.js
  4:3   warning  Unexpected var, use let or const instead  no-var
  5:29  warning  Unexpected function expression            prefer-arrow-callback
  8:7   warning  Expected property shorthand               object-shorthand
 10:12  warning  Unexpected function expression            prefer-arrow-callback
 13:7   warning  Expected property shorthand               object-shorthand

The warnings seem to be about code that would be injected by Babel, but ESLint runs with enforce: pre, so looks like double processing. This happens only for the worker the rest of the code is built correctly.

Here's the (simplified) code for my worker:

import process from './process';

self.onmessage = ({data}) =>
    process(data)
        .then(result => postMessage({type: 'success', result}))
        .catch(error => postMessage({type: 'error', error}));

This could be related to the problem reported in #86.

kamaladenalhomsi commented 3 years ago

+1

dohun-toss commented 3 years ago

I think you should add that file in .eslintignore

jcestibariz commented 3 years ago

@dohun-toss I'm sorry that's not acceptable. I need to lint my worker.

dohun-toss commented 3 years ago

@jcestibariz Are you using eslint-loader? I think you want to use enforce: pre option. But, if you give up enforce: pre option, there are 2 alternatives: eslint-webpack-plugin or changing order of two loaders.

dohun-toss commented 3 years ago
module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['babel-loader', 'eslint-loader'], // without enforce pre, you can use lint first
      },
    ],
  },
  // ...
};

but, eslint-loader is deprecated. how about trying to migrate to eslint-webpack-plugin?

Before:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: {
          // eslint options (if necessary)
        },
      },
    ],
  },
  // ...
};

After:

const ESLintPlugin = require('eslint-webpack-plugin');

module.exports = {
  // ...
  plugins: [new ESLintPlugin(options)],
  // ...
};
jcestibariz commented 3 years ago

@dohun-toss I had not noticed that eslint-loader was deprecated. Using eslint-webpack-plugin fixed the problem, thank you!