Skip to content

Commit 628a497

Browse files
committed
'no-leaked-event-listener' does not report handlers with a singal arg, closes #1282
1 parent 2a460f0 commit 628a497

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

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

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,24 @@ ruleTester.run(RULE_NAME, rule, {
146146
},
147147
],
148148
},
149-
{
150-
code: tsx`
151-
function Example() {
152-
useEffect(() => {
153-
const ab = new AbortController();
154-
window.addEventListener("resize", () => {}, { signal: ab.signal });
155-
return () => {
156-
// ab.abort();
157-
};
158-
}, []);
159-
}
160-
`,
161-
errors: [
162-
{
163-
messageId: "expectedRemoveEventListenerInCleanup",
164-
},
165-
],
166-
},
149+
// {
150+
// code: tsx`
151+
// function Example() {
152+
// useEffect(() => {
153+
// const ab = new AbortController();
154+
// window.addEventListener("resize", () => {}, { signal: ab.signal });
155+
// return () => {
156+
// // ab.abort();
157+
// };
158+
// }, []);
159+
// }
160+
// `,
161+
// errors: [
162+
// {
163+
// messageId: "expectedRemoveEventListenerInCleanup",
164+
// },
165+
// ],
166+
// },
167167
{
168168
code: tsx`
169169
function Example() {
@@ -385,50 +385,50 @@ ruleTester.run(RULE_NAME, rule, {
385385
},
386386
],
387387
},
388-
{
389-
code: tsx`
390-
const abortController = new AbortController();
391-
function Example() {
392-
const rHandleResize = useRef(() => {});
393-
useEffect(() => {
394-
window.addEventListener("focus", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController.signal });
395-
window.addEventListener("resize", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController.signal });
396-
return () => {
397-
// abortController.abort();
398-
};
399-
}, []);
400-
}
401-
`,
402-
errors: [
403-
{
404-
messageId: "expectedRemoveEventListenerInCleanup",
405-
},
406-
{
407-
messageId: "expectedRemoveEventListenerInCleanup",
408-
},
409-
],
410-
},
411-
{
412-
code: tsx`
413-
const abortController1 = new AbortController();
414-
const abortController2 = new AbortController();
415-
function Example() {
416-
const rHandleResize = useRef(() => {});
417-
useEffect(() => {
418-
window.addEventListener("focus", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController1.signal });
419-
window.addEventListener("resize", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController2.signal });
420-
return () => {
421-
abortController1.abort();
422-
};
423-
}, []);
424-
}
425-
`,
426-
errors: [
427-
{
428-
messageId: "expectedRemoveEventListenerInCleanup",
429-
},
430-
],
431-
},
388+
// {
389+
// code: tsx`
390+
// const abortController = new AbortController();
391+
// function Example() {
392+
// const rHandleResize = useRef(() => {});
393+
// useEffect(() => {
394+
// window.addEventListener("focus", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController.signal });
395+
// window.addEventListener("resize", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController.signal });
396+
// return () => {
397+
// // abortController.abort();
398+
// };
399+
// }, []);
400+
// }
401+
// `,
402+
// errors: [
403+
// {
404+
// messageId: "expectedRemoveEventListenerInCleanup",
405+
// },
406+
// {
407+
// messageId: "expectedRemoveEventListenerInCleanup",
408+
// },
409+
// ],
410+
// },
411+
// {
412+
// code: tsx`
413+
// const abortController1 = new AbortController();
414+
// const abortController2 = new AbortController();
415+
// function Example() {
416+
// const rHandleResize = useRef(() => {});
417+
// useEffect(() => {
418+
// window.addEventListener("focus", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController1.signal });
419+
// window.addEventListener("resize", rHandleResize.current, { once: false, passive: true, capture: true, signal: abortController2.signal });
420+
// return () => {
421+
// abortController1.abort();
422+
// };
423+
// }, []);
424+
// }
425+
// `,
426+
// errors: [
427+
// {
428+
// messageId: "expectedRemoveEventListenerInCleanup",
429+
// },
430+
// ],
431+
// },
432432
{
433433
code: tsx`
434434
import { useEffect } from "react";

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
292292
["Program:exit"]() {
293293
for (const aEntry of aEntries) {
294294
const signal = aEntry.signal;
295-
if (signal != null && abortedSignals.some((a) => isSameObject(a, signal))) {
295+
// https://github.com/Rel1cx/eslint-react/issues/1282#issuecomment-3536511881
296+
// if (signal != null && abortedSignals.some((a) => isSameObject(a, signal))) {
297+
// continue;
298+
// }
299+
if (signal != null) {
296300
continue;
297301
}
298302
if (rEntries.some((rEntry) => isInverseEntry(aEntry, rEntry))) {

0 commit comments

Comments
 (0)