diff --git a/packages/core/src/hook/hook-hierarchy.ts b/packages/core/src/hook/hook-hierarchy.ts index d1786f1d1..3c165fd36 100644 --- a/packages/core/src/hook/hook-hierarchy.ts +++ b/packages/core/src/hook/hook-hierarchy.ts @@ -7,8 +7,6 @@ import { isUseEffectCallLoose } from "./hook-is"; export function isFunctionOfUseEffectSetup(node: TSESTree.Node | unit) { if (node == null) return false; return node.parent?.type === T.CallExpression - && node.parent.callee !== node - && node.parent.callee.type === T.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent); } diff --git a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts index 61626033f..050972d7a 100644 --- a/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts +++ b/packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts @@ -644,6 +644,27 @@ ruleTester.run(RULE_NAME, rule, { }, ], }, + { + code: tsx` + import * as React from 'react'; + + function useCustomHook() { + React.useEffect(() => { + const handleClick = () => { + console.log("clicked"); + }; + document.addEventListener("click", handleClick); + // ^^^^^^^^^^^^ + // - No error is reported here + }, []); + } + `, + errors: [ + { + messageId: "expectedRemoveEventListenerInCleanup", + }, + ], + }, ], valid: [ ...allValid,