Skip to content

fix(query-core): make sure we don't invoke select too often when using placeholderData #9007

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

Merged
merged 6 commits into from
Apr 12, 2025
Merged
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
178 changes: 90 additions & 88 deletions packages/eslint-plugin-query/src/__tests__/no-void-query-fn.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import { RuleTester } from '@typescript-eslint/rule-tester'
import { afterAll, describe, it } from 'vitest'
import { afterAll, describe, it, test } from 'vitest'
import { rule } from '../rules/no-void-query-fn/no-void-query-fn.rule'
import { normalizeIndent } from './test-utils'

Expand All @@ -18,11 +18,12 @@ const ruleTester = new RuleTester({
},
})

ruleTester.run('no-void-query-fn', rule, {
valid: [
{
name: 'queryFn returns a value',
code: normalizeIndent`
test('should run rule tests', () => {
ruleTester.run('no-void-query-fn', rule, {
valid: [
{
name: 'queryFn returns a value',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -33,10 +34,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn returns a Promise',
code: normalizeIndent`
},
{
name: 'queryFn returns a Promise',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -47,10 +48,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn returns Promise.resolve',
code: normalizeIndent`
},
{
name: 'queryFn returns Promise.resolve',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -61,10 +62,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn with explicit Promise type',
code: normalizeIndent`
},
{
name: 'queryFn with explicit Promise type',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

interface Data {
Expand All @@ -81,10 +82,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn with generic Promise type',
code: normalizeIndent`
},
{
name: 'queryFn with generic Promise type',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

interface Response<T> {
Expand All @@ -101,10 +102,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn with external async function',
code: normalizeIndent`
},
{
name: 'queryFn with external async function',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

async function fetchData(): Promise<{ data: string }> {
Expand All @@ -119,10 +120,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn returns null',
code: normalizeIndent`
},
{
name: 'queryFn returns null',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -133,10 +134,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn returns 0',
code: normalizeIndent`
},
{
name: 'queryFn returns 0',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -147,10 +148,10 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
{
name: 'queryFn returns false',
code: normalizeIndent`
},
{
name: 'queryFn returns false',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -161,12 +162,12 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
},
],
invalid: [
{
name: 'queryFn returns void',
code: normalizeIndent`
},
],
invalid: [
{
name: 'queryFn returns void',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -179,11 +180,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn returns undefined',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn returns undefined',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -194,11 +195,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'async queryFn returns void',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'async queryFn returns void',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -211,11 +212,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with explicit void Promise',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with explicit void Promise',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -228,11 +229,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with Promise.resolve(undefined)',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with Promise.resolve(undefined)',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -243,11 +244,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with external void async function',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with external void async function',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

async function voidOperation(): Promise<void> {
Expand All @@ -262,11 +263,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with conditional return (one branch missing)',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with conditional return (one branch missing)',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -282,11 +283,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with ternary operator returning undefined',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'queryFn with ternary operator returning undefined',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -297,11 +298,11 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'async queryFn with try/catch missing return in catch',
code: normalizeIndent`
errors: [{ messageId: 'noVoidReturn' }],
},
{
name: 'async queryFn with try/catch missing return in catch',
code: normalizeIndent`
import { useQuery } from '@tanstack/react-query'

function Component() {
Expand All @@ -319,7 +320,8 @@ ruleTester.run('no-void-query-fn', rule, {
return null
}
`,
errors: [{ messageId: 'noVoidReturn' }],
},
],
})
errors: [{ messageId: 'noVoidReturn' }],
},
],
})
}, 10_000)
Loading