A ESLint plugin for rspack
npm install eslint-rspack-plugin> This plugin was forked from the excellent eslint-webpack-plugin. Many thanks to the original authors for their great work.
This plugin uses ESLint to find and fix problems in your JavaScript code.
> You may find it more efficient to avoid using the eslint-rspack-plugin, as running ESLint during the build can lead to longer build times. A separate lint command usually offers a better workflow.
To begin, you'll need to install eslint-rspack-plugin:
``console`
npm install eslint-rspack-plugin --save-dev
or
`console`
yarn add -D eslint-rspack-plugin
or
`console`
pnpm add -D eslint-rspack-plugin
> [!NOTE]
>
> You also need to install eslint >= 8 from npm, if you haven't already:
`console`
npm install eslint --save-dev
or
`console`
yarn add -D eslint
or
`console`
pnpm add -D eslint
Then add the plugin to your Rspack config. For example:
`js
const ESLintPlugin = require('eslint-rspack-plugin');
module.exports = {
// ...
plugins: [new ESLintPlugin(options)],
// ...
};
`
You can pass eslint options.
> [!NOTE]
>
> The config option you provide will be passed to the ESLint class.package.json
> This is a different set of options than what you'd specify in or .eslintrc.
> See the eslint docs for more details.
- Type:
`ts`
type cache = boolean;
- Default: true
The cache is enabled by default to decrease execution time.
- Type:
`ts`
type cacheLocation = string;
- Default: node_modules/.cache/eslint-webpack-plugin/.eslintcache
Specify the path to the cache location. Can be a file or a directory.
- Type:
`ts`
type configType = 'flat' | 'eslintrc';
- Default: eslintrc
Specify the type of configuration to use with ESLint.
- eslintrc is the classic configuration format available in most ESLint versions.flat
- is the new format introduced in ESLint 8.21.0.
The new configuration format is explained in its own documentation.
> This configuration format being considered as experimental, it is not exported in the main ESLint module in ESLint 8.
> You need to set your eslintPath to eslint/use-at-your-own-risk for this config format to work.
- Type:
`ts`
type context = string;
- Default: compiler.context
A string indicating the root of your files.
- Type:
`ts`
type eslintPath = 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 don't have to install eslint.
- Type:
`ts`
type extensions = string | Array
- Default: 'js'
Specify extensions that should be checked.
- Type:
`ts`
type exclude = string | Array
- Default: 'node_modules'
Specify the files and/or directories to exclude. Must be relative to options.context.
- Type:
`ts`
type resourceQueryExclude = RegExp | Array
- Default: []
Specify the resource query to exclude.
- Type:
`ts`
type files = string | Array
- Default: null
Specify directories, files, or globs. Must be relative to options.context.options.extensions
Directories are traversed recursively looking for files matching .options.extensions
File and glob patterns ignore .
- Type:
`ts`
type fix = boolean;
- Default: false
Will enable ESLint autofix feature.
Be careful: this option will change source files.
- Type:
`ts`
type formatter = string| (
results: Array
data?: import('eslint').ESLint.LintResultData | undefined
) => string
- Default: 'stylish'
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.
- Type:
`ts`
type lintDirtyModulesOnly = boolean;
- Default: false
Lint only changed files, skip lint on start.
- Type:
`ts`
type lintAllFiles = boolean;
- Default: false
Lint all files matching the files and extensions patterns, regardless of whether they are part of the compilation.
> [!TIP]
> This option is particularly useful for multi-environment builds (e.g., Rsbuild/Rspack with separate client and server environments) where you want to ensure all files in your codebase are linted, not just the ones included in each environment's dependency graph.
>
> Enabling this option will run a single ESLint instance to check all files rather than running separate ESLint instances for each environment.
- Type:
`ts`
type threads = boolean | number;
- Default: false
Will run lint tasks across a thread pool. The pool size is automatic unless you specify a number.
By default the plugin will auto adjust error reporting depending on eslint errors/warnings counts.
You can still force this behavior by using emitError or emitWarning options:
#### emitError
- Type:
`ts`
type emitError = boolean;
- Default: true
The errors found will always be emitted, to disable set to false.
#### emitWarning
- Type:
`ts`
type emitWarning = boolean;
- Default: true
The warnings found will always be emitted, to disable set to false.
#### failOnError
- Type:
`ts`
type failOnError = boolean;
- Default: true
Will cause the module build to fail if there are any errors, to disable set to false.
#### failOnWarning
- Type:
`ts`
type failOnWarning = boolean;
- Default: false
Will cause the module build to fail if there are any warnings, if set to true.
#### quiet
- Type:
`ts`
type quiet = boolean;
- Default: false
Will process and report errors only and ignore warnings, if set to true.
#### outputReport
- Type:
`ts`
type outputReport =
| boolean
| {
filePath?: string | undefined;
formatter?:
| (
| string
| ((
results: Array
data?: import('eslint').ESLint.LintResultData | undefined,
) => string)
)
| undefined;
};
- Default: false
Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI.
The filePath is an absolute path or relative to the Rspack config: output.path.formatter` for the output file,
You can pass in a different
if none is passed in the default/configured formatter will be used.
[npm]: https://img.shields.io/npm/v/eslint-rspack-plugin.svg
[npm-url]: https://npmjs.com/package/eslint-rspack-plugin
[node]: https://img.shields.io/node/v/eslint-rspack-plugin.svg
[node-url]: https://nodejs.org