Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint v9 contains breaking API changes #3699

Open
2 tasks done
Tracked by #2961 ...
james-yeoman opened this issue Mar 4, 2024 · 22 comments
Open
2 tasks done
Tracked by #2961 ...

ESLint v9 contains breaking API changes #3699

james-yeoman opened this issue Mar 4, 2024 · 22 comments

Comments

@james-yeoman
Copy link

james-yeoman commented Mar 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Upon bumping to the ESLint beta for v9, I was met with several errors in my monorepo during the linting test-run.

Namely:

  • Error: context.getScope is not a function
    • Rule: "react/no-string-refs"
  • Error: context.getFirstTokens is not a function
    • Rule: "react/display-name"

I get that it's still only a beta, but these API changes were announced in september 2023.

Additionally, there are some rule structure changes outlined separately that may be worth ensuring are in compliance.

Expected Behavior

Given that ESLint v9 is now in beta, I wasn't expecting to find any plugins that haven't yet addressed the API changes

eslint-plugin-react version

v7.34.0

eslint version

v9.0.0-beta.1

node version

v18.12.0

@ljharb
Copy link
Member

ljharb commented Mar 4, 2024

That expectation is flawed; the point of it being in beta is for plugins to begin to address the changes - announcements are irrelevant. Thanks for the report.

A fix for this will also need to add eslint 9 into the test matrix.

@ljharb
Copy link
Member

ljharb commented Mar 4, 2024

I put up a branch running tests on eslint 9; https://github.com/ljharb/eslint-plugin-react/actions/runs/8147742013/job/22269131527#step:5:21 is failing because the jsx-no-undef and jsx-uses-react and jsx-uses-vars tests call linter.defineRule. @bmish, any thoughts on an approach here?

@ljharb
Copy link
Member

ljharb commented Mar 4, 2024

Additionally, when I comment out those 3 lines, i get 22166 failures because Error: ESLint configuration in rule-tester is invalid: Key "parserOptions": This appears to be in eslintrc format rather than flat config format.. Does this mean eslint 9 drops support for eslintrc, or it's just no longer the default?

If the former, how can we run the same tests with both normal eslintrc stuff on eslint 8, and also with flat config on eslint 9?

@james-yeoman
Copy link
Author

james-yeoman commented Mar 5, 2024

ESLint 9 makes the flat config the default. It renames the ESLintRC style classes to be LegacyESLint and the Linter requires an option of {configType: "eslintrc"}, and in ESLint 10, they plan on dropping the legacy config altogether.

There's a migration guide that might be a good place to start in terms of compiling a list of required tasks for this

@ljharb
Copy link
Member

ljharb commented Mar 6, 2024

Awesome, thanks for the pointers.

That will help get us unblocked for eslint 9, but we'll still have a lot of work to support eslint 10.

@james-yeoman
Copy link
Author

james-yeoman commented Apr 2, 2024

Is there any update on this yet? Or is this still quite far off? The first release candidate for v9 released last week

@ljharb
Copy link
Member

ljharb commented Apr 2, 2024

@james-yeoman it is almost never the case that all the plugins in the eslint ecosystem support a new major until awhile after the final release is out. It'd be great to beat that, but if there'd been any update, it'd be in this issue :-)

@JstnMcBrd
Copy link

Eslint officially released v9.0.0 today. Hope this plugin will support it soon!

@ljharb ljharb changed the title [Bug]: ESLint v9 contains breaking API changes ESLint v9 contains breaking API changes Apr 6, 2024
@ljharb ljharb removed the bug label Apr 6, 2024
@nodegin
Copy link

nodegin commented Apr 8, 2024

Getting TypeError: context.getScope is not a function here

@chelsea6502
Copy link

I'd like to continue using this plugin, but this bug is unfortunately stopping me.

I hope we get to see a fix soon!

@ljharb
Copy link
Member

ljharb commented Apr 11, 2024

Nobody’s forcing you to upgrade to eslint 9 right away ¯\_(ツ)_/¯ new eslint majors always take months before everything supports them, and this one will take longer because it’s changing the default config format.

@Standard8
Copy link

and this one will take longer because it’s changing the default config format.

Having worked on a couple of other plugins, I want to elaborate that I think there's two parts to this upgrade.

The real breaking change for v9 is the fact that v9 has removed APIs - it looks like this is being covered in #3727.

The second change is flat config compatibility. Consumers can use the plugin as-is (as long as the API issues are resolved). It is slightly more work, but it is possible. Of course, supporting the flat config natively makes it easier, and ESLint has a good migration guide should anyone wanting to upgrade to v9 feel like contributing a patch (I might eventually, but I have several other plugins that I'm focussing on).

@graue
Copy link

graue commented Apr 19, 2024

Thanks for your work on this plugin, @ljharb! Seems totally reasonable to take some time to support ESLint 9, and anyone who reeeeeeally needs to be on the latest and greatest should consider hiring you (if you're available for such work) or volunteering their time to make it happen. Since I'm not able to do that myself at the moment, I'm happy to wait to upgrade ESLint.

@danielweck
Copy link

Scott, that's a perfect answer :)
Thanks all!

@linusjf

This comment was marked as off-topic.

@linusjf
Copy link

linusjf commented Apr 22, 2024

The same problem occurs with eslint-plugin-solid. fyi.

TypeError: context.getScope is not a function Occurred while linting /data/data/com.termux/files/home/LearnSolidJS/FirstApp/src/FibCounter.tsx:15 Rule: "solid/reactivity" at checkForReactiveAssignment (/data/data/com.termux/files/home/LearnSolidJS/node_modules/eslint-plugin-solid/dist/rules/reactivity.js:445:69) at VariableDeclarator (/data/data/com.termux/files/home/LearnSolidJS/node_modules/eslint-plugin-solid/dist/rules/reactivity.js:768:11) at ruleErrorHandler (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/linter.js:1115:48) at /data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:58 at Array.forEach () at Object.emit (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/safe-emitter.js:45:38) at NodeEventGenerator.applySelector (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/node-event-generator.js:297:26) at NodeEventGenerator.applySelectors (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/node-event-generator.js:326:22) at NodeEventGenerator.enterNode (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/node-event-generator.js:340:14) at runRules (/data/data/com.termux/files/usr/lib/node_modules/eslint/lib/linter/linter.js:1154:40)

Reverted my global installation of eslint to 8.57.0. A case of TLDR;

@ljharb
Copy link
Member

ljharb commented Apr 23, 2024

Indeed, you simply can't upgrade to eslint 9 until all of your eslint plugins/configs have explicit peer dep support for it. (this is true for every eslint major)

@olaf-cichocki
Copy link

Hey, the reason for error (and backward's compatible implementation) can be found here: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()

As for sourceCode.getFirstTokens() it's here: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#from-context-to-sourcecode

@lucasprag
Copy link

Also getting the error for these rules:

    'react/no-direct-mutation-state': 0,
    'react/require-render-return': 0,
    'react/no-string-refs': 0,
    'react/jsx-uses-react': 0,
    'react/react-in-jsx-scope': 0,
    'react/no-danger-with-children': 0,
    'react/jsx-no-undef': 0,
    'react/jsx-uses-vars': 0,

@sethlivingston
Copy link

Thanks for all your hard work on this, maintainers.

Until support for eslint v9 is ready, you can create a fresh v8 config with:

npm install -D eslint@8
npm init @eslint/config@0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests