Skip to content

Commit 5191cec

Browse files
rename rule to "no-unstable-deps"
1 parent 8065447 commit 5191cec

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

docs/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@
794794
"to": "eslint/no-rest-destructuring"
795795
},
796796
{
797-
"label": "No Unstable Query/Mutation in Deps",
798-
"to": "eslint/no-unstable-query-mutation-in-deps"
797+
"label": "No Unstable Deps",
798+
"to": "eslint/no-unstable-deps"
799799
}
800800
]
801801
},

docs/eslint/eslint-plugin-query.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ Alternatively, add `@tanstack/eslint-plugin-query` to the plugins section, and c
9696
- [@tanstack/query/exhaustive-deps](../exhaustive-deps)
9797
- [@tanstack/query/no-rest-destructuring](../no-rest-destructuring)
9898
- [@tanstack/query/stable-query-client](../stable-query-client)
99-
- [@tanstack/query/no-unstable-query-mutation-in-deps](../no-unstable-query-mutation-in-deps.md)
99+
- [@tanstack/query/no-unstable-deps](../no-unstable-deps.md)

docs/eslint/no-unstable-query-mutation-in-deps.md renamed to docs/eslint/no-unstable-deps.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: no-unstable-query-mutation-in-deps
2+
id: no-unstable-deps
33
title: Disallow putting the result of query hooks directly in a React hook dependency array
44
---
55

@@ -21,7 +21,7 @@ Instead, destructure the return value of the query hook and pass the destructure
2121
Examples of **incorrect** code for this rule:
2222

2323
```tsx
24-
/* eslint "@tanstack/query/no-unstable-query-mutation-in-deps": "warn" */
24+
/* eslint "@tanstack/query/no-unstable-deps": "warn" */
2525
import { useCallback } from 'React'
2626
import { useMutation } from '@tanstack/react-query'
2727

@@ -37,7 +37,7 @@ function Component() {
3737
Examples of **correct** code for this rule:
3838

3939
```tsx
40-
/* eslint "@tanstack/query/no-unstable-query-mutation-in-deps": "warn" */
40+
/* eslint "@tanstack/query/no-unstable-deps": "warn" */
4141
import { useCallback } from 'React'
4242
import { useMutation } from '@tanstack/react-query'
4343

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
reactHookNames,
44
rule,
55
useQueryHookNames,
6-
} from '../rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule'
6+
} from '../rules/no-unstable-deps/no-unstable-deps.rule'
77

88
const ruleTester = new RuleTester({
99
parser: '@typescript-eslint/parser',
@@ -46,7 +46,11 @@ const baseTestCases = {
4646
`,
4747
})),
4848
),
49-
invalid: ({ reactHookImport, reactHookInvocation, reactHookAlias }: TestCase) =>
49+
invalid: ({
50+
reactHookImport,
51+
reactHookInvocation,
52+
reactHookAlias,
53+
}: TestCase) =>
5054
[
5155
{
5256
name: `result of useMutation is passed to ${reactHookInvocation} as dependency `,
@@ -62,7 +66,7 @@ const baseTestCases = {
6266
`,
6367
errors: [
6468
{
65-
messageId: 'noUnstableQueryMutationInDeps',
69+
messageId: 'noUnstableDeps',
6670
data: { reactHook: reactHookAlias, queryHook: 'useMutation' },
6771
},
6872
],
@@ -82,7 +86,7 @@ const baseTestCases = {
8286
`,
8387
errors: [
8488
{
85-
messageId: 'noUnstableQueryMutationInDeps',
89+
messageId: 'noUnstableDeps',
8690
data: { reactHook: reactHookAlias, queryHook },
8791
},
8892
],
@@ -111,7 +115,7 @@ const testCases = (reactHookName: string) => [
111115
reactHookNames.forEach((reactHookName) => {
112116
testCases(reactHookName).forEach(
113117
({ reactHookInvocation, reactHookAlias, reactHookImport }) => {
114-
ruleTester.run('no-unstable-query-mutation-in-deps', rule, {
118+
ruleTester.run('no-unstable-deps', rule, {
115119
valid: baseTestCases.valid({
116120
reactHookImport,
117121
reactHookInvocation,

packages/eslint-plugin-query/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Object.assign(plugin.configs, {
2828
'@tanstack/query/exhaustive-deps': 'error',
2929
'@tanstack/query/no-rest-destructuring': 'warn',
3030
'@tanstack/query/stable-query-client': 'error',
31-
'@tanstack/query/no-unstable-query-mutation-in-deps': 'error',
31+
'@tanstack/query/no-unstable-deps': 'error',
3232
},
3333
},
3434
'flat/recommended': [
@@ -40,7 +40,7 @@ Object.assign(plugin.configs, {
4040
'@tanstack/query/exhaustive-deps': 'error',
4141
'@tanstack/query/no-rest-destructuring': 'warn',
4242
'@tanstack/query/stable-query-client': 'error',
43-
'@tanstack/query/no-unstable-query-mutation-in-deps': 'error',
43+
'@tanstack/query/no-unstable-deps': 'error',
4444
},
4545
},
4646
],

packages/eslint-plugin-query/src/rules.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as exhaustiveDeps from './rules/exhaustive-deps/exhaustive-deps.rule'
22
import * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'
33
import * as noRestDestructuring from './rules/no-rest-destructuring/no-rest-destructuring.rule'
4-
import * as noUnstableQueryMutationInDeps from './rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule'
4+
import * as noUnstableDeps from './rules/no-unstable-deps/no-unstable-deps.rule'
55
import type { ESLintUtils } from '@typescript-eslint/utils'
66
import type { ExtraRuleDocs } from './types'
77

@@ -17,5 +17,5 @@ export const rules: Record<
1717
[exhaustiveDeps.name]: exhaustiveDeps.rule,
1818
[stableQueryClient.name]: stableQueryClient.rule,
1919
[noRestDestructuring.name]: noRestDestructuring.rule,
20-
[noUnstableQueryMutationInDeps.name]: noUnstableQueryMutationInDeps.rule,
20+
[noUnstableDeps.name]: noUnstableDeps.rule,
2121
}
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { detectTanstackQueryImports } from '../../utils/detect-react-query-impor
44
import type { TSESTree } from '@typescript-eslint/utils'
55
import type { ExtraRuleDocs } from '../../types'
66

7-
export const name = 'no-unstable-query-mutation-in-deps'
7+
export const name = 'no-unstable-deps'
88

99
export const reactHookNames = ['useEffect', 'useCallback', 'useMemo']
1010
export const useQueryHookNames = [
@@ -28,7 +28,7 @@ export const rule = createRule({
2828
recommended: 'error',
2929
},
3030
messages: {
31-
noUnstableQueryMutationInDeps: `The result of {{queryHook}} is not referentially stable, so don't pass it directly into the dependencies array of {{reactHook}}. Instead, destructure the return value of {{queryHook}} and pass the destructured values into the dependency array of {{reactHook}}.`,
31+
noUnstableDeps: `The result of {{queryHook}} is not referentially stable, so don't pass it directly into the dependencies array of {{reactHook}}. Instead, destructure the return value of {{queryHook}} and pass the destructured values into the dependency array of {{reactHook}}.`,
3232
},
3333
schema: [],
3434
},
@@ -113,7 +113,7 @@ export const rule = createRule({
113113
const queryHook = trackedVariables[dep.name]
114114
context.report({
115115
node: dep,
116-
messageId: 'noUnstableQueryMutationInDeps',
116+
messageId: 'noUnstableDeps',
117117
data: {
118118
queryHook,
119119
reactHook,

0 commit comments

Comments
 (0)