Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some false positive for prefer-query-object-syntax rule #5953

Conversation

eg-bernardo
Copy link

Fixes #5028, and cases where the query options object is not defined in the same file as the useQuery call.

To be able to test the issue with satisfies I had to update typescript and @typescript-eslint packages, but I have only updated devDependencies in eslint-plugin-query.

I have removed a test case for invalid code:

import { useQuery } from "@tanstack/react-query";
useQuery(queryKey);

Because I think in most cases for useQuery(some_variable) when some_variable is not defined in the current file, it will be a query options object.

@vercel
Copy link

vercel bot commented Sep 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2023 6:10am

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 4, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 653917f:

Sandbox Source
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

@nx-cloud
Copy link

nx-cloud bot commented Sep 5, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 653917f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


🟥 Failed Commands
nx affected --targets=test:eslint,test:lib,test:types,test:build
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Comment on lines +7 to +13
* We are using a newer version of typescript than the one at the repository root,
* to be able to test code that uses newer typescript features.
* To prevent RuleTester from using the typescript version at the root
* we resolve '@typescript-eslint/parser' here instead of letting it do it internally.
* Once the version at the root is updated to >=4.9 this can be replaced by just "@typescript-eslint/parser"
*/
parser: require.resolve('@typescript-eslint/parser') as any,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are we using an older version of @typescript-eslint/parser ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here:

"@typescript-eslint/parser": "^5.41.0",

I came to the conclusion that I also needed to update typescript to >=4.9 to be able to test satisfies and I didn't wan't to change the typescript version in the respository root. But maybe I can update @typescript-eslint in the root. I will give it another look.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried updating only @typescript-eslint/* packages to oldest version that suports satisfies (5.45.0), but that is not enough, typescript >=4.9 is also needed, otherwise the test that uses satisfies fails with A fatal parsing error occurred: Parsing error: ',' expected.

I didn't want to update the typescript version in the root, because I assumed that it is probably there to ensure that packages stay compatible with that version of typescript.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, I see. what we'd want is to develop with TS 5.2, but have a type-testing suite that works against all sorts of TS versions.

@ZackDeRose started with this some time back, but we never followed through:

I'll take a look at setting this up later this week, then we should be good without this workaround 👍

@Newbie012
Copy link
Collaborator

My personal take:
I think it would be wrong to remove the 2 tests, since useQuery(["query-key"]) is considered a valid syntax in older versions.
Last thing, consider adding another 2 separate tests - one with only as const and one with only satisfies.

Other than that, LGTM.

@eg-bernardo
Copy link
Author

I think githubs diff is not being very helpful, because I have only removed one test and added two here: 27b7153 and then added another here 331fa08. It's clearer in the diffs for the individual commits.

The test for useQuery(["queryKey"]) is still there

@TkDodo
Copy link
Collaborator

TkDodo commented Nov 28, 2023

@eg-bernardo can you please fix the conflicts than we can go ahead and merge this fix

@eg-bernardo
Copy link
Author

This PR is only relevant for v4 since prefer-query-object-syntax is no longer required on v5.

Also it was blocked because it required typescript 4.9:
#5953 (comment)

and you said:
#5953 (comment)

But it seems v4 still targets typescript 4.7.

@TkDodo
Copy link
Collaborator

TkDodo commented Nov 29, 2023

you're right, I'll close this then.

@TkDodo TkDodo closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESLint plugin does not work well with TypeScript satisfies
3 participants