query icon indicating copy to clipboard operation
query copied to clipboard

ESLint prefer-query-object-syntax does not catch issues in v4.36.1

Open raulpineda opened this issue 2 years ago • 6 comments

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

raulpineda avatar Dec 06 '23 15:12 raulpineda

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:

Screenshot 2023-12-12 at 11 07 14

so please maybe show a fully configured github repo because I think there's nothing wrong with the lint rule

TkDodo avatar Dec 12 '23 10:12 TkDodo

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 image

raulpineda avatar Dec 20 '23 14:12 raulpineda

this is so weird. The very same code errors in my project:

Screenshot 2023-12-20 at 16 03 50

Screenshot 2023-12-20 at 16 03 44

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.

TkDodo avatar Dec 20 '23 15:12 TkDodo

It seems like this rule doesn't work properly with ESLint's default parser Espree.

As a workaround, you could:

  1. temporarily npm install @typescript-eslint/parser
  2. set parser: "@typescript-eslint/parser", in your .eslintrc.js file
  3. 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.

Newbie012 avatar Dec 20 '23 18:12 Newbie012

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

raulpineda avatar Dec 20 '23 20:12 raulpineda

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.

TkDodo avatar Dec 21 '23 08:12 TkDodo