jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
8.86k stars 2.75k forks source link

[Bug]: 'React' must be in scope when using JSXeslintreact/react-in-jsx-scope #3770

Closed vaynevayne closed 1 week ago

vaynevayne commented 1 week ago

Is there an existing issue for this?

Description Overview

The eslint rule I just created, react18, actually prompts you to introduce react at the top. This should be the default option, right? Is this the rule intentional and I need to turn it off manually, or is there a problem with my configuration?

image
import { fixupConfigRules } from "@eslint/compat";
import pluginJs from '@eslint/js';
import pluginReactConfig from 'eslint-plugin-react/configs/recommended.js';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default [
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  {
    files: ['**/*.jsx'],
    languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
  },
  ...fixupConfigRules(pluginReactConfig),
  {
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
    },
  },
]

Expected Behavior

no error

eslint-plugin-react version

7.34.3

eslint version

^9.5.0

node version

v20.14.0

ljharb commented 1 week ago

This is by design - you need to extend the jsx-runtime config, as detailed in the readme here