jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
8.97k stars 2.77k forks source link

[Bug]: An incomprehensible mistake #3737

Closed root9464 closed 5 months ago

root9464 commented 5 months ago

Is there an existing issue for this?

Description Overview

PS C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test> npx eslint -c eslint.config.js
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .

Oops! Something went wrong! :(

ESLint: 9.0.0

TypeError: context.getScope is not a function
Occurred while linting C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\src\main.tsx:6
Rule: "react/no-string-refs"
    at Object.getParentES6Component (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint-plugin-react\lib\util\componentUtil.js:140:23)
    at isRefsUsage (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint-plugin-react\lib\rules\no-string-refs.js:52:24)
    at MemberExpression (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint-plugin-react\lib\rules\no-string-refs.js:101:13)
    at ruleErrorHandler (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\linter.js:1145:48)
    at C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\linter\node-event-generator.js:340:14)

I initialized the vite project bin create vite and then decided to update the eset bin client --init I created a new file eslint.config.js with unusual content for me

import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
import globals from "globals";
import tseslint from "typescript-eslint";

import { FlatCompat } from "@eslint/eslintrc";
import pluginJs from "@eslint/js";
import path from "path";
import { fileURLToPath } from "url";

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});

export default [
  {languageOptions: { globals: globals.browser }},
  ...compat.extends("xo-typescript"),
  ...tseslint.configs.recommended,
  pluginReactConfig,
];

Also in the debug console, this is

024-04-15T06:02:46.860Z eslintrc:cascading-config-array-factory Configuration was determined: ConfigArray(1) [ { type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: 'C:\\Users\\User\\Desktop\\Projects\\Frameworks\\ReactJS\\test', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined } ] on C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test
Uncaught exception received.
Error: No ESLint configuration found in C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test.
    at CascadingConfigArrayFactory._finalizeConfigArray (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:4000:19)
    at CascadingConfigArrayFactory.getConfigArrayForFile (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3791:21)
    at CLIEngine.isPathIgnored (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\cli-engine\cli-engine.js:1000:18)
    at ESLint.isPathIgnored (C:\Users\User\Desktop\Projects\Frameworks\ReactJS\test\node_modules\eslint\lib\eslint\eslint.js:681:26)
    at c:\Users\User\.vscode-insiders\extensions\dbaeumer.vscode-eslint-2.4.4\server\out\eslintServer.js:1:23905
    at Object.E [as withClass] (c:\Users\User\.vscode-insiders\extensions\dbaeumer.vscode-eslint-2.4.4\server\out\eslintServer.js:1:19120)
    at T.then.g.validate (c:\Users\User\.vscode-insiders\extensions\dbaeumer.vscode-eslint-2.4.4\server\out\eslintServer.js:1:23876)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async c:\Users\User\.vscode-insiders\extensions\dbaeumer.vscode-eslint-2.4.4\server\out\eslintServer.js:1:220163

To summarize, I can say that I do not understand what the error is, but I cannot switch to eslint v9 because of errors that I do not understand. If anyone can help please

Expected Behavior

I'm asking for help.

eslint-plugin-react version

eslint-plugin-react@7.34.1

eslint version

v9.0.0

node version

v20.11.1

duskrunner commented 5 months ago

Having same issue. Looks like some methods are deprecated. https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/

c3dr0x commented 5 months ago

A thread is open in this issue https://github.com/jsx-eslint/eslint-plugin-react/issues/3699

ljharb commented 5 months ago

Indeed, we don’t support eslint 9 yet - the declared peer deps should have warned you not to upgrade.

Duplicate of #3699.