Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nabla/vite-plugin-eslint

nabla214.9kMIT2.0.5TypeScript support: included

Plugs ESLint into Vite dev server

vite, eslint, vite-plugin

readme

@nabla/vite-plugin-eslint npm

Plugs ESLint into Vite dev server.

Differences with vite-plugin-eslint

  • Keeps HMR fast: linting is done asynchronously and doesn't block the transform process
  • Reduces noise: Display results via console logs

logs.png

Because of this, the plugin can't fail the build and is only applied in dev. Like typechecking, linting should be done before or in parallel of the build command.

Install

yarn add --dev @nabla/vite-plugin-eslint

Usage

import { defineConfig } from "vite";
import eslintPlugin from "@nabla/vite-plugin-eslint";

export default defineConfig({
  plugins: [eslintPlugin()],
});

Options

eslintOptions

Note: the fix option is only supported from 1.3.4

shouldLint

  • Type: (path: string) => boolean
  • Default: (path) => path.match(/\/src\/[^?]*\.(vue|svelte|m?[jt]sx?)$/)

You can use DEBUG=eslint node_modules/.bin/vite to debug this option (available in 1.4.0)

formatter

  • Type: string | ((result: ESLint.LintResult) => void)
  • Default: Custom format with one line per warning/error.

If provided, the value is passed to eslint.loadFormatter. Use stylish to get a CRA like output. Async formatters are supported in 1.5.0. Function support was added in 2.0.2.

changelog

Changelog

2.0.5

  • Add vite@6 to peer dependency range

2.0.4

  • Add explicit debug dependency
  • Change ESLint peer dependency range to ^8.45 || ^9 to match the changes made to support flat config in 2.0.2

2.0.2

  • Support ESLint flat config (fixes #23)
  • Support passing a function to formatter
  • Switch to ESM. This removes the CJS warning when using the plugin with Vite 5. A CJS wrapper is still provided but migrating to running Vite in ESM is encouraged
  • Drop support for Vite 2 & 3 & node<18 (aligns with Vite 5)

1.6.0

  • Add vite@5 to peer dependency range
  • Fix error when using errorOnUnmatchedPattern: false
  • Update plugin name from eslint to vite-plugin-eslint to avoid confusion in case of errors reported by Vite

1.5.0

  • Support async formatters (#17)
  • Add .svelte to default shouldLint regex

1.4.2

Add vite@4 to peer dependency range

1.4.1

Add vite@3 to peer dependency range

1.4.0

  • Update default shouldLint option to include .vue, .mjs & .mts files by default
  • Add debug log when a file is ignored by shouldLint (#7)

1.3.5

Pin chalk to v4 (#5)

1.3.4

Enable fix option (#3)

1.3.2

Handle file not found error

1.3.1

Move ESLint to a worker to improve performances