ESLint prefer-query-object-syntax does not catch issues in v4.36.1
Describe the bug
I configured prefer-query-object-syntax to error to make it easier to upgrade to v5 in the near future, but the eslint rule is not catching obvious errors
Your minimal, reproducible example
Minimal example in an eslint-online-playground
Steps to reproduce
install [email protected]
install "@tanstack/[email protected]"
configure prefer-query-object-syntax as error
write a function that uses useQuery with an unnamed first parameter as a key
Expected behavior
As a user, I expect useQuery(['an-unnamed-array-first-parameter']) to trigger the eslint rule error
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
MacOS VSCode 1.84.2 ESLint 8.55.0
Tanstack Query adapter
react-query
TanStack Query version
4.36.1
TypeScript version
No response
Additional context
No response
seems more like the rule doesn't work at all in this playground?
I just tried out v4.36.1 in one of our repos and it works just fine:
so please maybe show a fully configured github repo because I think there's nothing wrong with the lint rule
Apologies about the late reply. Here's the requested repo https://github.com/raulpineda/eslint-query-test
The prefer-query-object-syntax rule does not trigger, but exhaustive-deps does
this is so weird. The very same code errors in my project:
I'm not really sure how this is possible. @Newbie012 FYI.
@raulpineda please fix the lock file in the reproduction - it contains references to private registries that I couldn't pull from. Had to delete the lock file and re-create it, I think that's a left-over.
It seems like this rule doesn't work properly with ESLint's default parser Espree.
As a workaround, you could:
- temporarily
npm install @typescript-eslint/parser - set
parser: "@typescript-eslint/parser",in your.eslintrc.jsfile - run eslint again.
@TkDodo I can't find the rule's source code. I assume it was deleted in 5.0.0?
Edit - While we could try to fully support the Espree parser, I'm not sure if the existing rules (such as exhaustive-deps) would still be able to catch complex cases.
The lock file has been recreated. I can confirm that using the typescript eslint parser I see errors as expected.
The rule was indeed deleted in 5.0.0, since the object syntax is the only valid one
okay, then I'll once again close this issue because there is a workaround, and we likely won't invest more into a rule that is already deleted in the latest version.