eslint版本 9.9.0
vite版本 5.4.1
在vite中,配置了自动引入,但是eslint还是会报错ESLint: 'useState' is not defined.(no-undef),eslint应该怎么配置,求大佬告知
// vite.config.js
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import AutoImport from "unplugin-auto-import/vite"
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
AutoImport({
eslintrc: {
enabled: false,
filepath: "./.eslintrc-auto-import.json" //此文件为重新启动项目生成的文件
},
dts: "./auto-imports.d.ts",//此文件配置保存后系统自动生成
imports: ["react", "react-router"] //此处可填写需要自动引入的库
})
]
})
// eslint
export default [
{ignores: ["dist"]},
{
files: ["**/*.{js,jsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: "latest",
ecmaFeatures: {jsx: true},
sourceType: "module"
}
},
settings: {react: {version: "18.3"}},
plugins: {
react,
"react-hooks": reactHooks,
"react-refresh": reactRefresh
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs["jsx-runtime"].rules,
...reactHooks.configs.recommended.rules,
"react/jsx-no-target-blank": "off",
"react-refresh/only-export-components": [
"warn",
{allowConstantExport: true}
]
}
}
]
希望可以不用没有都写import { useState } from "react"这种引入
需要 "extends" : ['./.eslintrc-auto-import.json']