-
Notifications
You must be signed in to change notification settings - Fork 47k
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-plugin-react-hooks: Add support for ESLint v9 #28773
Conversation
80e7b49
to
c5b335e
Compare
Comparing: 699d03c...c1f1de3 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
43a0927
to
1a217e9
Compare
return context.sourceCode.getScope(node); | ||
} | ||
} | ||
|
||
const scopeManager = context.getSourceCode().scopeManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context-methods-becoming-properties
I noticed that this context.getSourceCode()
was replaced with context.sourceCode
, you might want to confirm that.
const sourceCode = context.sourceCode ?? context.getSourceCode();
const scopeManager = sourceCode.scopeManager;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getSourceCode
was only deprecated.
88687c4
to
e2da44f
Compare
yarn.lock
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe split this out into a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It kind of doesn't make sense for these change to stay if we revert ESlint v9 support. And if we need to revert the lockfile changes, we also need to revert ESLint v9 support.
Merge conflicts in yarn.lock are not an issue since you'd just run yarn
. Yarn automatically resolves merge conflicts.
I rebased this PR to isolate these changes so if we do need to bisect later, we can still do it on this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, sorry I missed that there was a package.json update
packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js
Outdated
Show resolved
Hide resolved
Will be used to test compat between eslint-plugin-react-hooks and ESLint v9
e2da44f
to
5d30424
Compare
…iveDeps-test.js Co-authored-by: lauren <poteto@users.noreply.github.com>
Any updates? Still waiting on this for our stack's ESLint 9 upgrade. |
yarn add eslint-plugin-react-hooks@5.1.0-rc-eb3ad065-20240822 -D |
when can we expect a release? |
Looks like we can install |
For who made this work: I'm using the rc version of 5.1.0, but still getting the same error. This is my config:
Am I doing something wrong? |
@c10b10 My working config
|
##### [v5.0.0](https://github.com/facebook/react/blob/HEAD/packages/eslint-plugin-react-hooks/CHANGELOG.md#500) - **New Violations:** Component names now need to start with an uppercase letter instead of a non-lowercase letter. This means `_Button` or `_component` are no longer valid. ([@kassens](https://github.com/kassens)) in [#25162](facebook/react#25162) <!----> - Consider dispatch from `useActionState` stable. ([@eps1lon](https://github.com/eps1lon) in [#29665](facebook/react#29665)) - Add support for ESLint v9. ([@eps1lon](https://github.com/eps1lon) in [#28773](facebook/react#28773)) - Accept `as` expression in callback. ([@StyleShit](https://github.com/StyleShit) in [#28202](facebook/react#28202)) - Accept `as` expressions in deps array. ([@StyleShit](https://github.com/StyleShit) in [#28189](facebook/react#28189)) - Treat `React.use()` the same as `use()`. ([@kassens](https://github.com/kassens) in [#27769](facebook/react#27769)) - Move `use()` lint to non-experimental. ([@kassens](https://github.com/kassens) in [#27768](facebook/react#27768)) - Support Flow `as` expressions. ([@cpojer](https://github.com/cpojer) in [#27590](facebook/react#27590)) - Allow `useEffect(fn, undefined)`. ([@kassens](https://github.com/kassens) in [#27525](facebook/react#27525)) - Disallow hooks in async functions. ([@acdlite](https://github.com/acdlite) in [#27045](facebook/react#27045)) - Rename experimental `useEvent` to `useEffectEvent`. ([@sebmarkbage](https://github.com/sebmarkbage) in [#25881](facebook/react#25881)) - Lint for presence of `useEvent` functions in dependency lists. ([@poteto](https://github.com/poteto) in [#25512](facebook/react#25512)) - Check `useEvent` references instead. ([@poteto](https://github.com/poteto) in [#25319](facebook/react#25319)) - Update `RulesOfHooks` with `useEvent` rules. ([@poteto](https://github.com/poteto) in [#25285](facebook/react#25285))
> [!WARNING] > **Breaking Change:** Now uses `eslint-plugin-react-hooks@5.0.0` which has a new violation disallowing Component names starting with anything but an uppercase letter. See https://github.com/facebook/react/releases/tag/eslint-plugin-react-hooks%405.0.0 for more details. Adds support of ESLint v9 to `eslint-plugin-next`, `eslint-config-next` and `next lint`. Does not require using the new flat config format. `next lint` will automatically ensure the old config format can be used. ### Why? As `eslint-plugin-react-hooks` has been updated for ESLint v9 support and is a helpful package for Next v15 upgrade, unblock the restrictions to upgrade to ESLint v9. Also, ESLint v8 is [End of Life](https://eslint.org/blog/2024/09/eslint-v8-eol-version-support/#:~:text=ESLint%20v8.-,x%20end%20of%20life%20is%20October%205%2C%202024,x%20on%20October%205%2C%202024.) support since Oct 5th, so is good to unblock v9 now. Plugins bumped: - [x] [@rushstack/eslint-patch](microsoft/rushstack#4719) ([v1.10.3](https://www.npmjs.com/package/@rushstack/eslint-patch/v/1.10.3?activeTab=versions) no release post, confirmed on NPM) - [x] [@typescript-eslint/eslint-plugin](typescript-eslint/typescript-eslint#9002) ([v8.0.0](typescript-eslint/typescript-eslint#9002 (comment))) - [x] [eslint-plugin-import](import-js/eslint-plugin-import#2996) ([v2.31.0](https://github.com/import-js/eslint-plugin-import/releases/tag/v2.31.0)) - [x] [eslint-plugin-jsx-a11y](jsx-eslint/eslint-plugin-jsx-a11y#1009) ([v6.10.0](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/releases/tag/v6.10.0)) - [x] [eslint-plugin-react](jsx-eslint/eslint-plugin-react#3759) ([v7.35.0](https://github.com/jsx-eslint/eslint-plugin-react/releases/tag/v7.35.0)) - [x] [eslint-plugin-react-hooks](facebook/react#28773) ([v5.0.0](https://github.com/facebook/react/releases/tag/eslint-plugin-react-hooks%405.0.0)) We have to switch to ESLint v9 in our repo due to a pnpm bug where it automatically uses ESLint v9 even though we only installed it via `eslint-v9: npm:eslint@9.0.0`. This is a pnpm bug that wouldn't happen with Yarn v1, v4 nor NPM. Closes #64409 Closes #64114 Closes #64453 Closes NEXT-3293 --------- Co-authored-by: Sebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
Released in |
My config for my Tanstack Start project import pluginRouter from "@tanstack/eslint-plugin-router";
import pluginReactHooks from "eslint-plugin-react-hooks";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";
import globals from "globals";
export default [
...pluginRouter.configs["flat/recommended"],
...tseslint.configs.recommended,
{
files: ["**/**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
...pluginReact.configs.flat.recommended,
languageOptions: {
...pluginReact.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
},
},
},
{
files: ["**/**/*.{js,ts,jsx,tsx}"],
plugins: {
"react-hooks": pluginReactHooks,
},
rules: {
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
...pluginReactHooks.configs.recommended.rules,
},
},
]; ESLint version: 9.12 Note that the eslint-plugin-react mentioned that:
So I configure the
I added some scripts to my "scripts": {
...
"lint": "npx eslint .",
"eslint-inspector": "npx @eslint/config-inspector@latest"
} You need to restart the ESLint server to make the ESLint extension work after getting things done. |
Based on #28774
Does not add support for flat configs i.e. does not adress #28313.
The PR only adds support for ESLint v9 with the old config format and sets up testing infra for separate ESLint versions. The only breaking changes that affected the plugin was around removal of
context.getScope
andcontext.getSource
which have simple replacements in V9 so that we don't have to fork too much to be able to support ESLint V9 and earlier.The last commit makes it so that we have no breaking changes. If we decide to drop support for ESLint < 9.x, we can just revert
80e7b49
(#28773)Alternate to #28772