Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-no-unstable-deps-prototype-lookups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/eslint-plugin-query': patch
---

Fix false-positive warnings in `no-unstable-deps` rule caused by `Object.prototype` property lookups (`toString`, `valueOf`, etc.).
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,55 @@ const baseTestCases = {
}
`,
},
{
name: `should pass when functions or variables with Object.prototype names are used with ${reactHookAlias}`,
code: `
${reactHookImport}
import { useQuery } from "@tanstack/react-query";

function Component() {
const toString = () => 'str';
const valueOf = 42;
const callback = ${reactHookInvocation}(() => { toString() }, [toString, valueOf]);
return;
}
`,
},
{
name: `should pass when custom functions named after Object.prototype methods are invoked`,
code: `
${reactHookImport}
import { useQuery } from "@tanstack/react-query";

function toString() {
return 'test';
}

function Component() {
const res = toString();
const callback = ${reactHookInvocation}(() => { res }, [res]);
return;
}
`,
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
{
name: `should pass when a local function named after Object.prototype method is called alongside destructured query result with ${reactHookAlias}`,
code: `
${reactHookImport}
import { useQuery } from "@tanstack/react-query";

function toString() {
return 'formatted';
}

function Component() {
const { data } = useQuery({ queryKey: ['test'], queryFn: () => 'test' });
const formatted = toString();
const callback = ${reactHookInvocation}(() => { formatted }, [data, formatted]);
return;
}
`,
},
]),
invalid: ({
reactHookImport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export const rule = createRule({
defaultOptions: [],

create: detectTanstackQueryImports((context, _options, helpers) => {
const trackedVariables: Record<string, string> = {}
const trackedCustomHooks: Record<string, string> = {}
const hookAliasMap: Record<string, string> = {}
const trackedVariables: Record<string, string> = Object.create(null)
const trackedCustomHooks: Record<string, string> = Object.create(null)
const hookAliasMap: Record<string, string> = Object.create(null)
const pendingVariableDeclarators: Array<TSESTree.VariableDeclarator> = []
const pendingDependencyChecks: Array<{
reactHook: string
Expand Down