Skip to content

eslint-plugin-vitest-globals

Vitest 全局变量 ESLint 插件

[GitHub]

简介

ESLint 插件,为 Vitest 全局变量提供支持,解决 ESLint 报 no-undef 错误的问题。

特性

  • ✅ 支持 Vitest 全局变量
  • ✅ 支持 ESLint 9+ Flat Config
  • ✅ 零配置开箱即用

安装

bash
# npm
npm install -D eslint-plugin-vitest-globals

# yarn
yarn add -D eslint-plugin-vitest-globals

# pnpm
pnpm add -D eslint-plugin-vitest-globals

使用

Flat Config (ESLint 9+)

js
// eslint.config.js
import vitestGlobals from 'eslint-plugin-vitest-globals'

export default [
  vitestGlobals.configs.recommended,
  // 或
  {
    plugins: {
      'vitest-globals': vitestGlobals
    },
    languageOptions: {
      globals: vitestGlobals.environments.globals
    }
  }
]

Legacy Config

js
// .eslintrc.js
module.exports = {
  plugins: ['vitest-globals'],
  env: {
    'vitest-globals/env': true
  }
}

支持的全局变量

  • describe, it, test, expect
  • beforeEach, afterEach, beforeAll, afterAll
  • vi, vitest
  • 以及更多 Vitest API...

统计

  • ⭐ Stars: 17
  • 📦 主要语言: JavaScript

MIT Licensed