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-lookup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/eslint-plugin-query': patch
---

Fix false positive in `no-unstable-deps` when a variable is assigned from a call whose name matches an `Object.prototype` method (e.g. `toString`, `valueOf`, `constructor`).
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,29 @@ reactHookNames.forEach((reactHookName) => {
},
)
})

const protoMethodNames = [
'toString',
'valueOf',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
] as const

ruleTester.run('no-unstable-deps', rule, {
valid: protoMethodNames.map((method) => ({
name: `should not flag variable from "${method}()" call as unstable dep`,
code: `
import { useCallback } from "React";

function Component() {
const result = ${method}();
const cb = useCallback(() => { result }, [result]);
return null;
}
`,
})),
invalid: [],
})
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export const rule = createRule({
}

if (callExpression.callee.type === AST_NODE_TYPES.Identifier) {
return trackedCustomHooks[callExpression.callee.name]
const calleeName = callExpression.callee.name
return Object.hasOwn(trackedCustomHooks, calleeName)
? trackedCustomHooks[calleeName]
: undefined
}

return undefined
Expand Down