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

相关推荐
我命由我123451 小时前
VSCode - VSCode 修改文件树缩进
前端·ide·vscode·前端框架·编辑器·html·js
white-persist2 小时前
VSCode 快捷键大全:从设计理念到场景化高效运用(详细解析)(文章末尾有vim快捷键大全)
linux·ide·vscode·python·编辑器·系统安全·vim
我命由我123453 小时前
VSCode - VSCode 颜色值快速转换
前端·ide·vscode·前端框架·编辑器·html·js
GISer_Jing5 小时前
React Native 2025:从零到精通实战指南
javascript·react native·react.js
酒尘6 小时前
React交互学习篇
react.js
KKKK6 小时前
一次React19.2 Activity 组件使用问题排查
react.js
BD_Marathon6 小时前
【JavaWeb】VsCode中快速生成HTML5模板
ide·vscode·html5
wordbaby7 小时前
React 误区粉碎:useEffectEvent 是“非响应式”的,所以它不会触发重渲染?
前端·react.js
海阔的天空8 小时前
VSCode通过continue插件免费安装AI模型实现自动编程
运维·ide·人工智能·vscode·编辑器·ai编程
crary,记忆8 小时前
React 之 useEffect
前端·javascript·学习·react.js