Describe the bug
In https://github.com/TanStack/query/blob/main/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts#L83 an identifier is only de-referenced if the target is an array.
This was written when the rule wasn't able to handle key factories (see TODO near the original commit: 82adc95#diff-1db59b20778c62ed3511c0664212006c2217e7c1ca7d07b79062b6e93fa3fc8b )
I wold think identifiers can always be de-referenced?
Anyway, this causes code like this
function queryKeyFactory(dependency: string) {
return ["my-key", dependency];
}
function example(dependency: string) {
const queryKey = queryKeyFactory(dependency);
return queryOptions({
queryKey,
queryFn: () => Promise.resolve(dependency),
})
}
to fail with "error The following dependencies are missing in your queryKey: dependency"
Note that there's a similar issue for as-expression in the same file in line 72.
Your minimal, reproducible example
https://eslint-online-playground.netlify.app/#eNp9UstuwjAQ/BXLlwSJhFPVioqqUisuPbQ9Yw6Rs0GGxE5tBxGh/HvXD4XQCk55eGZ2ZtZnajRfwKlo2hryvaFLKppWaUvO5KcD3X+2VihpyEAqrRrC6KstpLEFPyw0FNxmHsXoM5NMVp3kDh6oH9CvEaF0n5bQgixB8n5GzkwSosF2WpINo02fHQAF5uQC2qLa4ATh5L2MutHofz2OHu04lqzuOUDx0cA0Y+qVyEidTz7XcknSGVm9kC+sQRjINRhVH6+seMIwQ+90TsHUQtocjVVi96fZEioh4c0fXZoNjEVg+EYjoa27nZDfzkfAJpclBFIWIGEZCTJjcTio6Gr/HAemzuUmZMvzfCIezZpNUtWFxf1y1TQuXJlsfbYtk649TNfi7GLnboySmMw3x6jtW2B0iW+NKrsa3z2N0bEkAcYBYtPT2+StZ1zpqPCQPz3kj4z6TkeZ4/tNpVjf3v9mFBOAsdGBA4TzG4d3C73meENux8MvUHEhcw==
Steps to reproduce
- Open ESLint Playground
- Observe error message in problems tab
- (optional) inline either
queryKey variable or queryKeyFactory function to see error disappear
Expected behavior
As a developer I would like to be able to combine variables with functions for query keys without ESLint errors.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
vanilla
TanStack Query version
5.83.1
TypeScript version
No response
Additional context
No response
Describe the bug
In https://github.com/TanStack/query/blob/main/packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts#L83 an identifier is only de-referenced if the target is an array.
This was written when the rule wasn't able to handle key factories (see TODO near the original commit: 82adc95#diff-1db59b20778c62ed3511c0664212006c2217e7c1ca7d07b79062b6e93fa3fc8b )
I wold think identifiers can always be de-referenced?
Anyway, this causes code like this
to fail with "error The following dependencies are missing in your queryKey: dependency"
Note that there's a similar issue for as-expression in the same file in line 72.
Your minimal, reproducible example
https://eslint-online-playground.netlify.app/#eNp9UstuwjAQ/BXLlwSJhFPVioqqUisuPbQ9Yw6Rs0GGxE5tBxGh/HvXD4XQCk55eGZ2ZtZnajRfwKlo2hryvaFLKppWaUvO5KcD3X+2VihpyEAqrRrC6KstpLEFPyw0FNxmHsXoM5NMVp3kDh6oH9CvEaF0n5bQgixB8n5GzkwSosF2WpINo02fHQAF5uQC2qLa4ATh5L2MutHofz2OHu04lqzuOUDx0cA0Y+qVyEidTz7XcknSGVm9kC+sQRjINRhVH6+seMIwQ+90TsHUQtocjVVi96fZEioh4c0fXZoNjEVg+EYjoa27nZDfzkfAJpclBFIWIGEZCTJjcTio6Gr/HAemzuUmZMvzfCIezZpNUtWFxf1y1TQuXJlsfbYtk649TNfi7GLnboySmMw3x6jtW2B0iW+NKrsa3z2N0bEkAcYBYtPT2+StZ1zpqPCQPz3kj4z6TkeZ4/tNpVjf3v9mFBOAsdGBA4TzG4d3C73meENux8MvUHEhcw==
Steps to reproduce
queryKeyvariable orqueryKeyFactoryfunction to see error disappearExpected behavior
As a developer I would like to be able to combine variables with functions for query keys without ESLint errors.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
vanilla
TanStack Query version
5.83.1
TypeScript version
No response
Additional context
No response