-
Notifications
You must be signed in to change notification settings - Fork 49k
[eslint-plugin-react-hooks][RulesOfHooks] handle React.useEffect in addition to useEffect #34076
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
base: main
Are you sure you want to change the base?
Conversation
@@ -48,6 +48,7 @@ | |||
}, | |||
"devDependencies": { | |||
"@babel/eslint-parser": "^7.11.4", | |||
"babel-plugin-react-compiler": "link:../../compiler/packages/babel-plugin-react-compiler", |
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.
@@ -129,6 +132,24 @@ function isInsideTryCatch( | |||
return false; | |||
} | |||
|
|||
function getNodeWithoutReactNamespace( |
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.
Copied over from ExhaustiveDeps.ts
return node; | ||
} | ||
|
||
function isUseEffectIdentifier(node: Node): boolean { |
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.
I could have kept the code inlined, but it makes it a bit more readable
Summary
This is a fix for #34074
How did you test this change?
I added tests in the eslint package, and ran
yarn jest
. After adding the new tests, I have this:Changes
link:
to theeslint-plugin-react-hooks
pointing tobabel-plugin-react-compiler
otherwise it wouldn't run locallyCallExpression
(useEffect(
), andMemberExpression
(React.useEffect(
). To do that, I copied thegetNodeWithoutReactNamespace(
fn fromExhaustiveDeps.ts
toRulesOfHooks.ts