Skip to content

Commit 8b12e3c

Browse files
feat: support eslint v8
1 parent c472440 commit 8b12e3c

17 files changed

+10976
-14800
lines changed

.github/workflows/nodejs.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ name: eslint-webpack-plugin
33
on:
44
push:
55
branches:
6-
- master
7-
- next
6+
- 2.x
87
pull_request:
98
branches:
10-
- master
11-
- next
9+
- 2.x
1210

1311
jobs:
1412
lint:
@@ -43,8 +41,8 @@ jobs:
4341
- name: Lint
4442
run: npm run lint
4543

46-
- name: Security audit
47-
run: npm run security
44+
#- name: Security audit
45+
# run: npm run security
4846

4947
- name: Check commit message
5048
uses: wagoid/commitlint-github-action@v1
@@ -56,7 +54,11 @@ jobs:
5654
matrix:
5755
os: [ubuntu-latest, windows-latest, macos-latest]
5856
node-version: [10.x, 12.x, 14.x]
57+
eslint-version: [7.x, 8.x]
5958
webpack-version: [4, latest]
59+
exclude:
60+
- node-version: 10.x
61+
eslint-version: 8.x
6062

6163
runs-on: ${{ matrix.os }}
6264

@@ -86,6 +88,9 @@ jobs:
8688
- name: Install webpack ${{ matrix.webpack-version }}
8789
run: npm i webpack@${{ matrix.webpack-version }}
8890

91+
- name: Install eslint ${{ matrix.eslint-version }}
92+
run: npm i eslint@${{ matrix.eslint-version }}
93+
8994
- name: Run tests for webpack version ${{ matrix.webpack-version }}
9095
run: npm run test:coverage -- --ci
9196

README.md

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,11 @@
1313

1414
# eslint-webpack-plugin
1515

16-
> A ESLint plugin for webpack
16+
This plugin uses [`eslint`](https://eslint.org/) to find and fix problems in your JavaScript code
1717

18-
## About plugin
18+
## Getting Started
1919

20-
The plugin was born with the purpose of solving some problems of the [eslint-loader](https://github.com/webpack-contrib/eslint-loader).
21-
22-
| | eslint-webpack-plugin | eslint-loader |
23-
| -------------------------------- | :-------------------: | :----------------------: |
24-
| Easy configuration | :heavy_check_mark: | :heavy_multiplication_x: |
25-
| Generate unique an output report | :heavy_check_mark: | :heavy_multiplication_x: |
26-
| Using cache directly from eslint | :heavy_check_mark: | :heavy_multiplication_x: |
27-
| Lint only changed files | :heavy_check_mark: | :heavy_multiplication_x: |
28-
29-
## Migrate from `eslint-loader`
30-
31-
The loader `eslint-loader` will be deprecated soon, please use this plugin instead.
32-
33-
Before:
34-
35-
```js
36-
module.exports = {
37-
// ...
38-
module: {
39-
rules: [
40-
{
41-
test: /\.js$/,
42-
exclude: /node_modules/,
43-
loader: 'eslint-loader',
44-
options: {
45-
// eslint options (if necessary)
46-
},
47-
},
48-
],
49-
},
50-
// ...
51-
};
52-
```
53-
54-
After:
55-
56-
```js
57-
const ESLintPlugin = require('eslint-webpack-plugin');
58-
59-
module.exports = {
60-
// ...
61-
plugins: [new ESLintPlugin(options)],
62-
// ...
63-
};
64-
```
65-
66-
## Install
20+
To begin, you'll need to install `eslint-webpack-plugin`:
6721

6822
```bash
6923
npm install eslint-webpack-plugin --save-dev
@@ -75,9 +29,7 @@ npm install eslint-webpack-plugin --save-dev
7529
npm install eslint --save-dev
7630
```
7731

78-
## Usage
79-
80-
In your webpack configuration:
32+
Then add the plugin to your webpack config. For example:
8133

8234
```js
8335
const ESLintPlugin = require('eslint-webpack-plugin');
@@ -91,11 +43,11 @@ module.exports = {
9143

9244
## Options
9345

94-
You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options).
46+
You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
9547

9648
Note that the config option you provide will be passed to the `ESLint` class.
9749
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
98-
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options) for more details.
50+
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) for more details.
9951

10052
**Warning**: In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
10153

@@ -111,7 +63,7 @@ A string indicating the root of your files.
11163
- Type: `String`
11264
- Default: `eslint`
11365

114-
Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint`.
66+
Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you don't have to install `eslint`.
11567

11668
### `extensions`
11769

@@ -133,15 +85,15 @@ Specify the files and/or directories to exclude. Must be relative to `options.co
13385
- Default: `null`
13486

13587
Specify directories, files, or globs. Must be relative to `options.context`.
136-
Directories are traveresed recursively looking for files matching `options.extensions`.
88+
Directories are traversed recursively looking for files matching `options.extensions`.
13789
File and glob patterns ignore `options.extensions`.
13890

13991
### `fix`
14092

14193
- Type: `Boolean`
14294
- Default: `false`
14395

144-
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-eslint-outputfixes-results).
96+
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#-eslintoutputfixesresults).
14597

14698
**Be careful: this option will change source files.**
14799

declarations/ESLintError.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
export default ESLintError;
2-
declare class ESLintError extends Error {
3-
/**
4-
* @param {string=} messages
5-
*/
6-
constructor(messages?: string | undefined);
7-
}
2+
declare class ESLintError extends Error {}

declarations/cjs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
declare const _exports: typeof plugin.default;
22
export = _exports;
3-
import plugin = require('.');
3+
import plugin = require('./');

declarations/getESLint.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export default function getESLint(
3232
): Linter;
3333
export type ESLint = import('eslint').ESLint;
3434
export type LintResult = import('eslint').ESLint.LintResult;
35-
export type Options = import('./options').PluginOptions &
36-
import('eslint').ESLint.Options;
35+
export type Options = import('./options').Options;
3736
export type AsyncTask = () => Promise<void>;
3837
export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
3938
export type Worker = JestWorker & {
@@ -46,4 +45,4 @@ export type Linter = {
4645
lintFiles: LintTask;
4746
cleanup: AsyncTask;
4847
};
49-
import JestWorker from 'jest-worker';
48+
import { Worker as JestWorker } from 'jest-worker';

declarations/index.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export default ESLintWebpackPlugin;
22
export type Compiler = import('webpack').Compiler;
3-
export type Options = import('./options').PluginOptions &
4-
import('eslint').ESLint.Options;
3+
export type Options = import('./options').Options;
54
declare class ESLintWebpackPlugin {
65
/**
76
* @param {Options} options
@@ -11,8 +10,16 @@ declare class ESLintWebpackPlugin {
1110
options: import('./options').PluginOptions;
1211
/**
1312
* @param {Compiler} compiler
13+
* @param {Options} options
14+
* @param {string[]} wanted
15+
* @param {string[]} exclude
1416
*/
15-
run(compiler: Compiler): Promise<void>;
17+
run(
18+
compiler: Compiler,
19+
options: Options,
20+
wanted: string[],
21+
exclude: string[]
22+
): Promise<void>;
1623
/**
1724
* @param {Compiler} compiler
1825
* @returns {void}

declarations/linter.d.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ export type Formatter = import('eslint').ESLint.Formatter;
1818
export type LintResult = import('eslint').ESLint.LintResult;
1919
export type Compiler = import('webpack').Compiler;
2020
export type Compilation = import('webpack').Compilation;
21-
export type Source = import('webpack-sources/lib/Source');
22-
export type Options = import('./options').PluginOptions &
23-
import('eslint').ESLint.Options;
24-
export type FormatterFunction = (
25-
results: import('eslint').ESLint.LintResult[],
26-
data?: import('eslint').ESLint.LintResultData | undefined
27-
) => string;
21+
export type Options = import('./options').Options;
22+
export type FormatterFunction = import('./options').FormatterFunction;
2823
export type GenerateReport = (compilation: Compilation) => Promise<void>;
2924
export type Report = {
30-
errors?: ESLintError | undefined;
31-
warnings?: ESLintError | undefined;
32-
generateReportAsset?: GenerateReport | undefined;
25+
errors?: ESLintError;
26+
warnings?: ESLintError;
27+
generateReportAsset?: GenerateReport;
3328
};
3429
export type Reporter = () => Promise<Report>;
3530
export type Linter = (files: string | string[]) => void;

declarations/options.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ export type PluginOptions = {
6969
outputReport?: OutputReport | undefined;
7070
threads?: (number | boolean) | undefined;
7171
};
72-
export type Options = PluginOptions & import('eslint').ESLint.Options;
72+
export type Options = PluginOptions & ESLintOptions;

0 commit comments

Comments
 (0)