| [9af201e] | 1 | <div align="center">
|
|---|
| 2 | <a href="https://github.com/eslint/eslint"><img width="200" height="200" src="https://cdn.worldvectorlogo.com/logos/eslint.svg"></a>
|
|---|
| 3 | <a href="https://github.com/webpack/webpack"><img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"></a>
|
|---|
| 4 | </div>
|
|---|
| 5 |
|
|---|
| 6 | [![npm][npm]][npm-url]
|
|---|
| 7 | [![node][node]][node-url]
|
|---|
| 8 | [![tests][tests]][tests-url]
|
|---|
| 9 | [![coverage][cover]][cover-url]
|
|---|
| 10 | [![chat][chat]][chat-url]
|
|---|
| 11 | [![size][size]][size-url]
|
|---|
| 12 |
|
|---|
| 13 | # eslint-webpack-plugin
|
|---|
| 14 |
|
|---|
| 15 | > This is eslint-webpack-plugin 3.0 which works only with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/eslint-webpack-plugin/tree/2.x).
|
|---|
| 16 |
|
|---|
| 17 | This plugin uses [`eslint`](https://eslint.org/) to find and fix problems in your JavaScript code
|
|---|
| 18 |
|
|---|
| 19 | ## Getting Started
|
|---|
| 20 |
|
|---|
| 21 | To begin, you'll need to install `eslint-webpack-plugin`:
|
|---|
| 22 |
|
|---|
| 23 | ```console
|
|---|
| 24 | npm install eslint-webpack-plugin --save-dev
|
|---|
| 25 | ```
|
|---|
| 26 |
|
|---|
| 27 | or
|
|---|
| 28 |
|
|---|
| 29 | ```console
|
|---|
| 30 | yarn add -D eslint-webpack-plugin
|
|---|
| 31 | ```
|
|---|
| 32 |
|
|---|
| 33 | or
|
|---|
| 34 |
|
|---|
| 35 | ```console
|
|---|
| 36 | pnpm add -D eslint-webpack-plugin
|
|---|
| 37 | ```
|
|---|
| 38 |
|
|---|
| 39 | > **Note**
|
|---|
| 40 | >
|
|---|
| 41 | > You also need to install `eslint >= 7` from npm, if you haven't already:
|
|---|
| 42 |
|
|---|
| 43 | ```console
|
|---|
| 44 | npm install eslint --save-dev
|
|---|
| 45 | ```
|
|---|
| 46 |
|
|---|
| 47 | or
|
|---|
| 48 |
|
|---|
| 49 | ```console
|
|---|
| 50 | yarn add -D eslint
|
|---|
| 51 | ```
|
|---|
| 52 |
|
|---|
| 53 | or
|
|---|
| 54 |
|
|---|
| 55 | ```console
|
|---|
| 56 | pnpm add -D eslint
|
|---|
| 57 | ```
|
|---|
| 58 |
|
|---|
| 59 | Then add the plugin to your webpack config. For example:
|
|---|
| 60 |
|
|---|
| 61 | ```js
|
|---|
| 62 | const ESLintPlugin = require('eslint-webpack-plugin');
|
|---|
| 63 |
|
|---|
| 64 | module.exports = {
|
|---|
| 65 | // ...
|
|---|
| 66 | plugins: [new ESLintPlugin(options)],
|
|---|
| 67 | // ...
|
|---|
| 68 | };
|
|---|
| 69 | ```
|
|---|
| 70 |
|
|---|
| 71 | ## Options
|
|---|
| 72 |
|
|---|
| 73 | You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
|
|---|
| 74 |
|
|---|
| 75 | > **Note**
|
|---|
| 76 | >
|
|---|
| 77 | > The config option you provide will be passed to the `ESLint` class.
|
|---|
| 78 | > This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
|
|---|
| 79 | > See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) for more details.
|
|---|
| 80 |
|
|---|
| 81 | > **Warning**:
|
|---|
| 82 | >
|
|---|
| 83 | > In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
|
|---|
| 84 |
|
|---|
| 85 | ### `context`
|
|---|
| 86 |
|
|---|
| 87 | - Type:
|
|---|
| 88 |
|
|---|
| 89 | ```ts
|
|---|
| 90 | type context = string;
|
|---|
| 91 | ```
|
|---|
| 92 |
|
|---|
| 93 | - Default: `compiler.context`
|
|---|
| 94 |
|
|---|
| 95 | A string indicating the root of your files.
|
|---|
| 96 |
|
|---|
| 97 | ### `eslintPath`
|
|---|
| 98 |
|
|---|
| 99 | - Type:
|
|---|
| 100 |
|
|---|
| 101 | ```ts
|
|---|
| 102 | type eslintPath = string;
|
|---|
| 103 | ```
|
|---|
| 104 |
|
|---|
| 105 | - Default: `eslint`
|
|---|
| 106 |
|
|---|
| 107 | 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`.
|
|---|
| 108 |
|
|---|
| 109 | ### `extensions`
|
|---|
| 110 |
|
|---|
| 111 | - Type:
|
|---|
| 112 |
|
|---|
| 113 | ```ts
|
|---|
| 114 | type extensions = string | Array<string>;
|
|---|
| 115 | ```
|
|---|
| 116 |
|
|---|
| 117 | - Default: `'js'`
|
|---|
| 118 |
|
|---|
| 119 | Specify extensions that should be checked.
|
|---|
| 120 |
|
|---|
| 121 | ### `exclude`
|
|---|
| 122 |
|
|---|
| 123 | - Type:
|
|---|
| 124 |
|
|---|
| 125 | ```ts
|
|---|
| 126 | type exclude = string | Array<string>;
|
|---|
| 127 | ```
|
|---|
| 128 |
|
|---|
| 129 | - Default: `'node_modules'`
|
|---|
| 130 |
|
|---|
| 131 | Specify the files and/or directories to exclude. Must be relative to `options.context`.
|
|---|
| 132 |
|
|---|
| 133 | ### `resourceQueryExclude`
|
|---|
| 134 |
|
|---|
| 135 | - Type:
|
|---|
| 136 |
|
|---|
| 137 | ```ts
|
|---|
| 138 | type resourceQueryExclude = RegExp | Array<RegExp>;
|
|---|
| 139 | ```
|
|---|
| 140 |
|
|---|
| 141 | - Default: `[]`
|
|---|
| 142 |
|
|---|
| 143 | Specify the resource query to exclude.
|
|---|
| 144 |
|
|---|
| 145 | ### `files`
|
|---|
| 146 |
|
|---|
| 147 | - Type:
|
|---|
| 148 |
|
|---|
| 149 | ```ts
|
|---|
| 150 | type files = string | Array<string>;
|
|---|
| 151 | ```
|
|---|
| 152 |
|
|---|
| 153 | - Default: `null`
|
|---|
| 154 |
|
|---|
| 155 | Specify directories, files, or globs. Must be relative to `options.context`.
|
|---|
| 156 | Directories are traversed recursively looking for files matching `options.extensions`.
|
|---|
| 157 | File and glob patterns ignore `options.extensions`.
|
|---|
| 158 |
|
|---|
| 159 | ### `fix`
|
|---|
| 160 |
|
|---|
| 161 | - Type:
|
|---|
| 162 |
|
|---|
| 163 | ```ts
|
|---|
| 164 | type fix = boolean;
|
|---|
| 165 | ```
|
|---|
| 166 |
|
|---|
| 167 | - Default: `false`
|
|---|
| 168 |
|
|---|
| 169 | Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#-eslintoutputfixesresults).
|
|---|
| 170 |
|
|---|
| 171 | **Be careful: this option will change source files.**
|
|---|
| 172 |
|
|---|
| 173 | ### `formatter`
|
|---|
| 174 |
|
|---|
| 175 | - Type:
|
|---|
| 176 |
|
|---|
| 177 | ```ts
|
|---|
| 178 | type formatter = string| (
|
|---|
| 179 | results: Array<import('eslint').ESLint.LintResult>,
|
|---|
| 180 | data?: import('eslint').ESLint.LintResultData | undefined
|
|---|
| 181 | ) => string
|
|---|
| 182 | ```
|
|---|
| 183 |
|
|---|
| 184 | - Default: `'stylish'`
|
|---|
| 185 |
|
|---|
| 186 | Accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).
|
|---|
| 187 |
|
|---|
| 188 | ### `lintDirtyModulesOnly`
|
|---|
| 189 |
|
|---|
| 190 | - Type:
|
|---|
| 191 |
|
|---|
| 192 | ```ts
|
|---|
| 193 | type lintDirtyModulesOnly = boolean;
|
|---|
| 194 | ```
|
|---|
| 195 |
|
|---|
| 196 | - Default: `false`
|
|---|
| 197 |
|
|---|
| 198 | Lint only changed files, skip lint on start.
|
|---|
| 199 |
|
|---|
| 200 | ### `threads`
|
|---|
| 201 |
|
|---|
| 202 | - Type:
|
|---|
| 203 |
|
|---|
| 204 | ```ts
|
|---|
| 205 | type threads = boolean | number;
|
|---|
| 206 | ```
|
|---|
| 207 |
|
|---|
| 208 | - Default: `false`
|
|---|
| 209 |
|
|---|
| 210 | Will run lint tasks across a thread pool. The pool size is automatic unless you specify a number.
|
|---|
| 211 |
|
|---|
| 212 | ### Errors and Warning
|
|---|
| 213 |
|
|---|
| 214 | **By default the plugin will auto adjust error reporting depending on eslint errors/warnings counts.**
|
|---|
| 215 | You can still force this behavior by using `emitError` **or** `emitWarning` options:
|
|---|
| 216 |
|
|---|
| 217 | #### `emitError`
|
|---|
| 218 |
|
|---|
| 219 | - Type:
|
|---|
| 220 |
|
|---|
| 221 | ```ts
|
|---|
| 222 | type emitError = boolean;
|
|---|
| 223 | ```
|
|---|
| 224 |
|
|---|
| 225 | - Default: `true`
|
|---|
| 226 |
|
|---|
| 227 | The errors found will always be emitted, to disable set to `false`.
|
|---|
| 228 |
|
|---|
| 229 | #### `emitWarning`
|
|---|
| 230 |
|
|---|
| 231 | - Type:
|
|---|
| 232 |
|
|---|
| 233 | ```ts
|
|---|
| 234 | type emitWarning = boolean;
|
|---|
| 235 | ```
|
|---|
| 236 |
|
|---|
| 237 | - Default: `true`
|
|---|
| 238 |
|
|---|
| 239 | The warnings found will always be emitted, to disable set to `false`.
|
|---|
| 240 |
|
|---|
| 241 | #### `failOnError`
|
|---|
| 242 |
|
|---|
| 243 | - Type:
|
|---|
| 244 |
|
|---|
| 245 | ```ts
|
|---|
| 246 | type failOnError = boolean;
|
|---|
| 247 | ```
|
|---|
| 248 |
|
|---|
| 249 | - Default: `true`
|
|---|
| 250 |
|
|---|
| 251 | Will cause the module build to fail if there are any errors, to disable set to `false`.
|
|---|
| 252 |
|
|---|
| 253 | #### `failOnWarning`
|
|---|
| 254 |
|
|---|
| 255 | - Type:
|
|---|
| 256 |
|
|---|
| 257 | ```ts
|
|---|
| 258 | type failOnWarning = boolean;
|
|---|
| 259 | ```
|
|---|
| 260 |
|
|---|
| 261 | - Default: `false`
|
|---|
| 262 |
|
|---|
| 263 | Will cause the module build to fail if there are any warnings, if set to `true`.
|
|---|
| 264 |
|
|---|
| 265 | #### `quiet`
|
|---|
| 266 |
|
|---|
| 267 | - Type:
|
|---|
| 268 |
|
|---|
| 269 | ```ts
|
|---|
| 270 | type quiet = boolean;
|
|---|
| 271 | ```
|
|---|
| 272 |
|
|---|
| 273 | - Default: `false`
|
|---|
| 274 |
|
|---|
| 275 | Will process and report errors only and ignore warnings, if set to `true`.
|
|---|
| 276 |
|
|---|
| 277 | #### `outputReport`
|
|---|
| 278 |
|
|---|
| 279 | - Type:
|
|---|
| 280 |
|
|---|
| 281 | ```ts
|
|---|
| 282 | type outputReport =
|
|---|
| 283 | | boolean
|
|---|
| 284 | | {
|
|---|
| 285 | filePath?: string | undefined;
|
|---|
| 286 | formatter?:
|
|---|
| 287 | | (
|
|---|
| 288 | | string
|
|---|
| 289 | | ((
|
|---|
| 290 | results: Array<import('eslint').ESLint.LintResult>,
|
|---|
| 291 | data?: import('eslint').ESLint.LintResultData | undefined
|
|---|
| 292 | ) => string)
|
|---|
| 293 | )
|
|---|
| 294 | | undefined;
|
|---|
| 295 | };
|
|---|
| 296 | ```
|
|---|
| 297 |
|
|---|
| 298 | - Default: `false`
|
|---|
| 299 |
|
|---|
| 300 | Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI.
|
|---|
| 301 |
|
|---|
| 302 | The `filePath` is an absolute path or relative to the webpack config: `output.path`.
|
|---|
| 303 | You can pass in a different `formatter` for the output file,
|
|---|
| 304 | if none is passed in the default/configured formatter will be used.
|
|---|
| 305 |
|
|---|
| 306 | ## Changelog
|
|---|
| 307 |
|
|---|
| 308 | [Changelog](CHANGELOG.md)
|
|---|
| 309 |
|
|---|
| 310 | ## License
|
|---|
| 311 |
|
|---|
| 312 | [MIT](./LICENSE)
|
|---|
| 313 |
|
|---|
| 314 | [npm]: https://img.shields.io/npm/v/eslint-webpack-plugin.svg
|
|---|
| 315 | [npm-url]: https://npmjs.com/package/eslint-webpack-plugin
|
|---|
| 316 | [node]: https://img.shields.io/node/v/eslint-webpack-plugin.svg
|
|---|
| 317 | [node-url]: https://nodejs.org
|
|---|
| 318 | [tests]: https://github.com/webpack-contrib/eslint-webpack-plugin/workflows/eslint-webpack-plugin/badge.svg
|
|---|
| 319 | [tests-url]: https://github.com/webpack-contrib/eslint-webpack-plugin/actions
|
|---|
| 320 | [cover]: https://codecov.io/gh/webpack-contrib/eslint-webpack-plugin/branch/master/graph/badge.svg
|
|---|
| 321 | [cover-url]: https://codecov.io/gh/webpack-contrib/eslint-webpack-plugin
|
|---|
| 322 | [chat]: https://badges.gitter.im/webpack/webpack.svg
|
|---|
| 323 | [chat-url]: https://gitter.im/webpack/webpack
|
|---|
| 324 | [size]: https://packagephobia.now.sh/badge?p=eslint-webpack-plugin
|
|---|
| 325 | [size-url]: https://packagephobia.now.sh/result?p=eslint-webpack-plugin
|
|---|