diff --git a/docs/no-react-deps.md b/docs/no-react-deps.md index 9119d21..108e254 100644 --- a/docs/no-react-deps.md +++ b/docs/no-react-deps.md @@ -80,6 +80,11 @@ createEffect((prev) => { return (prev || 0) + 1; }); +createEffect((prev) => { + console.log(signal()); + return prev ? prev + 1 : 1; +}, undefined); + const value = createMemo(() => computeExpensiveValue(a(), b())); const sum = createMemo((prev) => input() + prev, 0); diff --git a/docs/reactivity.md b/docs/reactivity.md index 4c56be9..07c6296 100644 --- a/docs/reactivity.md +++ b/docs/reactivity.md @@ -537,6 +537,11 @@ createEffect(() => { runWithOwner(owner, () => console.log(signal())); }); +const [signal] = createSignal(); +createEffect(() => { + runWithOwner(undefined, () => console.log(signal())); +}); + const [signal] = createSignal(); createEffect(() => { [1, 2].forEach(() => console.log(signal())); diff --git a/src/utils.ts b/src/utils.ts index 2983ae3..bb3e0f8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -50,7 +50,9 @@ export function trace(node: T.Node, initialScope: TSESLint.Scope.Scope): T.Node if (!variable) return node; const def = variable.defs[0]; - switch (def.type) { + + // def is `undefined` for Identifier `undefined` + switch (def?.type) { case "FunctionName": case "ClassName": case "ImportBinding": diff --git a/test/rules/no-react-deps.test.ts b/test/rules/no-react-deps.test.ts index 300acd8..605de48 100644 --- a/test/rules/no-react-deps.test.ts +++ b/test/rules/no-react-deps.test.ts @@ -14,6 +14,10 @@ export const cases = run("no-react-deps", rule, { console.log(signal()); return (prev || 0) + 1; });`, + `createEffect((prev) => { + console.log(signal()); + return prev ? prev + 1 : 1; + }, undefined);`, `const value = createMemo(() => computeExpensiveValue(a(), b()));`, `const sum = createMemo((prev) => input() + prev, 0);`, `const args = [() => { console.log(signal()); }, [signal()]]; diff --git a/test/rules/reactivity.test.ts b/test/rules/reactivity.test.ts index 23c24e3..f315828 100644 --- a/test/rules/reactivity.test.ts +++ b/test/rules/reactivity.test.ts @@ -95,6 +95,10 @@ export const cases = run("reactivity", rule, { const owner = getOwner(); runWithOwner(owner, () => console.log(signal())); });`, + `const [signal] = createSignal(); + createEffect(() => { + runWithOwner(undefined, () => console.log(signal())); + });`, // Sync callbacks `const [signal] = createSignal(); createEffect(() => {