vscode+react+ESLint解决不引入组件,vscode不会报错的问题

解决不引入组件,vscode不会报错的问题

typescript 复制代码
routes.jsx       全部代码如下
export const routes = [
    {
        path:"/",
        element:<Home/>
    }
]

在项目根目录下新建个

eslint.config.js

加入下面的代码,要保证node_modules里安装了
eslint-plugin-react (主要是这个)

eslint-plugin-react-hooks

eslint-plugin-react-refresh

typescript 复制代码
import js from "@eslint/js";
import globals from "globals";
import reactPlugin from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";

export default [
  { ignores: ["dist", "build", "node_modules"] },
  {
    files: ["**/*.{js,jsx}"],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
      parserOptions: {
        ecmaVersion: "latest",
        sourceType: "module",
        ecmaFeatures: { jsx: true },
      },
    },
    settings: { react: { version: "detect" } },
    plugins: {
      react: reactPlugin,
      "react-hooks": reactHooks,
      "react-refresh": reactRefresh,
    },
    rules: {
      ...js.configs.recommended.rules,
      ...reactPlugin.configs.recommended.rules, // ← 插件推荐里包含 jsx-no-undef 等
      ...reactHooks.configs.recommended.rules,
      "no-unused-vars": "off", // 关掉 ESLint 对未使用变量的默认规则(如果已开启的话)
      // 如果想手动写,也可以:
      // 'react/jsx-no-undef': 'error',
      // 'react/jsx-uses-vars': 'error',
      // 'react/jsx-uses-react': 'error',
      // 'no-undef': 'error',
    },
  },
];

然后安装插件ESLint

相关推荐
电脑能手5 小时前
如何远程访问在WSL运行的Jupyter Notebook
ide·python·jupyter
前端小趴菜055 小时前
React - createPortal
前端·vue.js·react.js
迷路爸爸1806 小时前
让 VSCode 调试器像 PyCharm 一样显示 Tensor Shape、变量形状、变量长度、维度信息
ide·vscode·python·pycharm·debug·调试
爱编程的喵9 小时前
React Router Dom 初步:从传统路由到现代前端导航
前端·react.js
每天吃饭的羊9 小时前
react中为啥使用剪头函数
前端·javascript·react.js
谢尔登10 小时前
【React Native】样式、网络请求和Loading
网络·react native·react.js
TimelessHaze11 小时前
深入理解 JavaScript Event Loop:从原理到实战全解析
前端·javascript·react.js
G等你下课11 小时前
为什么你需要 useLayoutEffect?深入理解同步副作用
前端·react.js
Jackson_Mseven11 小时前
🎯 面试官:React 并发更新怎么调度的?我:Lane 就是调度界的 bitmap!
前端·react.js·面试
遂心_11 小时前
#React Router Dom 入门:构建现代单页面应用的前端路由方案
前端·javascript·react.js