Skip to content

Commit

Permalink
feat: support eslint v8
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Nov 12, 2021
1 parent c472440 commit 8b12e3c
Show file tree
Hide file tree
Showing 17 changed files with 10,976 additions and 14,800 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: eslint-webpack-plugin
on:
push:
branches:
- master
- next
- 2.x
pull_request:
branches:
- master
- next
- 2.x

jobs:
lint:
Expand Down Expand Up @@ -43,8 +41,8 @@ jobs:
- name: Lint
run: npm run lint

- name: Security audit
run: npm run security
#- name: Security audit
# run: npm run security

- name: Check commit message
uses: wagoid/commitlint-github-action@v1
Expand All @@ -56,7 +54,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x]
eslint-version: [7.x, 8.x]
webpack-version: [4, latest]
exclude:
- node-version: 10.x
eslint-version: 8.x

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

Expand Down Expand Up @@ -86,6 +88,9 @@ jobs:
- name: Install webpack ${{ matrix.webpack-version }}
run: npm i webpack@${{ matrix.webpack-version }}

- name: Install eslint ${{ matrix.eslint-version }}
run: npm i eslint@${{ matrix.eslint-version }}

- name: Run tests for webpack version ${{ matrix.webpack-version }}
run: npm run test:coverage -- --ci

Expand Down
66 changes: 9 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,11 @@

# eslint-webpack-plugin

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

## About plugin
## Getting Started

The plugin was born with the purpose of solving some problems of the [eslint-loader](https://github.com/webpack-contrib/eslint-loader).

| | eslint-webpack-plugin | eslint-loader |
| -------------------------------- | :-------------------: | :----------------------: |
| Easy configuration | :heavy_check_mark: | :heavy_multiplication_x: |
| Generate unique an output report | :heavy_check_mark: | :heavy_multiplication_x: |
| Using cache directly from eslint | :heavy_check_mark: | :heavy_multiplication_x: |
| Lint only changed files | :heavy_check_mark: | :heavy_multiplication_x: |

## Migrate from `eslint-loader`

The loader `eslint-loader` will be deprecated soon, please use this plugin instead.

Before:

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

After:

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

module.exports = {
// ...
plugins: [new ESLintPlugin(options)],
// ...
};
```

## Install
To begin, you'll need to install `eslint-webpack-plugin`:

```bash
npm install eslint-webpack-plugin --save-dev
Expand All @@ -75,9 +29,7 @@ npm install eslint-webpack-plugin --save-dev
npm install eslint --save-dev
```

## Usage

In your webpack configuration:
Then add the plugin to your webpack config. For example:

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

## Options

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

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

**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).

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

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`.
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`.

### `extensions`

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

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

### `fix`

- Type: `Boolean`
- Default: `false`

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

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

Expand Down
7 changes: 1 addition & 6 deletions declarations/ESLintError.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export default ESLintError;
declare class ESLintError extends Error {
/**
* @param {string=} messages
*/
constructor(messages?: string | undefined);
}
declare class ESLintError extends Error {}
2 changes: 1 addition & 1 deletion declarations/cjs.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare const _exports: typeof plugin.default;
export = _exports;
import plugin = require('.');
import plugin = require('./');
5 changes: 2 additions & 3 deletions declarations/getESLint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export default function getESLint(
): Linter;
export type ESLint = import('eslint').ESLint;
export type LintResult = import('eslint').ESLint.LintResult;
export type Options = import('./options').PluginOptions &
import('eslint').ESLint.Options;
export type Options = import('./options').Options;
export type AsyncTask = () => Promise<void>;
export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
export type Worker = JestWorker & {
Expand All @@ -46,4 +45,4 @@ export type Linter = {
lintFiles: LintTask;
cleanup: AsyncTask;
};
import JestWorker from 'jest-worker';
import { Worker as JestWorker } from 'jest-worker';
13 changes: 10 additions & 3 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default ESLintWebpackPlugin;
export type Compiler = import('webpack').Compiler;
export type Options = import('./options').PluginOptions &
import('eslint').ESLint.Options;
export type Options = import('./options').Options;
declare class ESLintWebpackPlugin {
/**
* @param {Options} options
Expand All @@ -11,8 +10,16 @@ declare class ESLintWebpackPlugin {
options: import('./options').PluginOptions;
/**
* @param {Compiler} compiler
* @param {Options} options
* @param {string[]} wanted
* @param {string[]} exclude
*/
run(compiler: Compiler): Promise<void>;
run(
compiler: Compiler,
options: Options,
wanted: string[],
exclude: string[]
): Promise<void>;
/**
* @param {Compiler} compiler
* @returns {void}
Expand Down
15 changes: 5 additions & 10 deletions declarations/linter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ export type Formatter = import('eslint').ESLint.Formatter;
export type LintResult = import('eslint').ESLint.LintResult;
export type Compiler = import('webpack').Compiler;
export type Compilation = import('webpack').Compilation;
export type Source = import('webpack-sources/lib/Source');
export type Options = import('./options').PluginOptions &
import('eslint').ESLint.Options;
export type FormatterFunction = (
results: import('eslint').ESLint.LintResult[],
data?: import('eslint').ESLint.LintResultData | undefined
) => string;
export type Options = import('./options').Options;
export type FormatterFunction = import('./options').FormatterFunction;
export type GenerateReport = (compilation: Compilation) => Promise<void>;
export type Report = {
errors?: ESLintError | undefined;
warnings?: ESLintError | undefined;
generateReportAsset?: GenerateReport | undefined;
errors?: ESLintError;
warnings?: ESLintError;
generateReportAsset?: GenerateReport;
};
export type Reporter = () => Promise<Report>;
export type Linter = (files: string | string[]) => void;
Expand Down
2 changes: 1 addition & 1 deletion declarations/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ export type PluginOptions = {
outputReport?: OutputReport | undefined;
threads?: (number | boolean) | undefined;
};
export type Options = PluginOptions & import('eslint').ESLint.Options;
export type Options = PluginOptions & ESLintOptions;

0 comments on commit 8b12e3c

Please sign in to comment.