Skip to content

Commit 84df72f

Browse files
authored
fix: fix useEffect setup function check in web-api/no-leaked-event-listener, closes #1228 (#1229)
1 parent 75663c9 commit 84df72f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/core/src/hook/hook-hierarchy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { isUseEffectCallLoose } from "./hook-is";
77
export function isFunctionOfUseEffectSetup(node: TSESTree.Node | unit) {
88
if (node == null) return false;
99
return node.parent?.type === T.CallExpression
10-
&& node.parent.callee !== node
11-
&& node.parent.callee.type === T.Identifier
1210
&& node.parent.arguments.at(0) === node
1311
&& isUseEffectCallLoose(node.parent);
1412
}

packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-event-listener.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,27 @@ ruleTester.run(RULE_NAME, rule, {
644644
},
645645
],
646646
},
647+
{
648+
code: tsx`
649+
import * as React from 'react';
650+
651+
function useCustomHook() {
652+
React.useEffect(() => {
653+
const handleClick = () => {
654+
console.log("clicked");
655+
};
656+
document.addEventListener("click", handleClick);
657+
// ^^^^^^^^^^^^
658+
// - No error is reported here
659+
}, []);
660+
}
661+
`,
662+
errors: [
663+
{
664+
messageId: "expectedRemoveEventListenerInCleanup",
665+
},
666+
],
667+
},
647668
],
648669
valid: [
649670
...allValid,

0 commit comments

Comments
 (0)