ESLint
Installation
- Make sure eslint and related plugins for your
eslintrcare installed as peer dependencies.
WARNING
Check out if version less than 0.7.1.
(Optional but highly recommended) Install optionator@^0.9.1 with your package manager. It's needed because of ESLint dependents on it. It's probably working fine even it's not installed as it's accessed as a phantom dependency. But when you set hoist=false of pnpm. It won't be accessible anymore without explicit installation.
From 0.7.1, the plugin will resolve optionator from eslint's path, so no more need to install it explicitly.
- Add
eslintfield to plugin config andoptions.eslint.lintCommandis required. ThelintCommandis the same as the lint command of your project. The default root of the command uses Vite's root.
TIP
Do not add --fix to the lint command since the plugin is only aiming at checking issues.
// e.g.
export default {
plugins: [
checker({
eslint: {
// for example, lint .ts and .tsx
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
},
}),
],
}Performance Optimization
If you're experiencing EMFILE: too many open files errors or want to improve performance, you can use the watchPath option to limit file watching to specific directories:
export default {
plugins: [
checker({
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
// Single directory
watchPath: './src',
// Multiple directories
// watchPath: ['./src', './lib'],
},
}),
],
}Configuration
Advanced object configuration table of options.eslint
| field | Type | Default value | Description |
|---|---|---|---|
| lintCommand | string | This value is required | lintCommand will be executed at build mode, and will also be used as default config for dev mode when eslint.dev.eslint is nullable. |
| watchPath | string | string[] | undefined | (Only in dev mode) Configure path to watch files for ESLint. If not specified, will watch the entire project root. Use this to improve performance and avoid EMFILE: too many open files errors. |
| useFlatConfig | boolean | false | If true, the plugin will use the new flat config of ESLint. |
| dev.overrideConfig | ESLint.Options | undefined | (Only in dev mode) You can override the options of the translated from lintCommand. Config priority: const eslint = new ESLint({cwd: root, ...translatedOptions, ...pluginConfig.eslint.dev?.overrideConfig, }). |
| dev.logLevel | ('error' | 'warning')[] | ['error', 'warning'] | (Only in dev mode) Which level of ESLint should be emitted to terminal and overlay in dev mode |