Skip to content

Commit

Permalink
rename rule to "no-unstable-deps"
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel committed Aug 19, 2024
1 parent dd1ce96 commit ce75bc4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@
"to": "eslint/no-rest-destructuring"
},
{
"label": "No Unstable Query/Mutation in Deps",
"to": "eslint/no-unstable-query-mutation-in-deps"
"label": "No Unstable Deps",
"to": "eslint/no-unstable-deps"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/eslint/eslint-plugin-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ Alternatively, add `@tanstack/eslint-plugin-query` to the plugins section, and c
- [@tanstack/query/exhaustive-deps](../exhaustive-deps)
- [@tanstack/query/no-rest-destructuring](../no-rest-destructuring)
- [@tanstack/query/stable-query-client](../stable-query-client)
- [@tanstack/query/no-unstable-query-mutation-in-deps](../no-unstable-query-mutation-in-deps.md)
- [@tanstack/query/no-unstable-deps](../no-unstable-deps.md)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: no-unstable-query-mutation-in-deps
id: no-unstable-deps
title: Disallow putting the result of query hooks directly in a React hook dependency array
---

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
reactHookNames,
rule,
useQueryHookNames,
} from '../rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule'
} from '../rules/no-unstable-deps/no-unstable-deps.rule'

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -46,7 +46,11 @@ const baseTestCases = {
`,
})),
),
invalid: ({ reactHookImport, reactHookInvocation, reactHookAlias }: TestCase) =>
invalid: ({
reactHookImport,
reactHookInvocation,
reactHookAlias,
}: TestCase) =>
[
{
name: `result of useMutation is passed to ${reactHookInvocation} as dependency `,
Expand Down Expand Up @@ -111,7 +115,7 @@ const testCases = (reactHookName: string) => [
reactHookNames.forEach((reactHookName) => {
testCases(reactHookName).forEach(
({ reactHookInvocation, reactHookAlias, reactHookImport }) => {
ruleTester.run('no-unstable-query-mutation-in-deps', rule, {
ruleTester.run('no-unstable-deps', rule, {
valid: baseTestCases.valid({
reactHookImport,
reactHookInvocation,
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Object.assign(plugin.configs, {
'@tanstack/query/exhaustive-deps': 'error',
'@tanstack/query/no-rest-destructuring': 'warn',
'@tanstack/query/stable-query-client': 'error',
'@tanstack/query/no-unstable-query-mutation-in-deps': 'error',
'@tanstack/query/no-unstable-deps': 'error',
},
},
'flat/recommended': [
Expand All @@ -40,7 +40,7 @@ Object.assign(plugin.configs, {
'@tanstack/query/exhaustive-deps': 'error',
'@tanstack/query/no-rest-destructuring': 'warn',
'@tanstack/query/stable-query-client': 'error',
'@tanstack/query/no-unstable-query-mutation-in-deps': 'error',
'@tanstack/query/no-unstable-deps': 'error',
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-query/src/rules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as exhaustiveDeps from './rules/exhaustive-deps/exhaustive-deps.rule'
import * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'
import * as noRestDestructuring from './rules/no-rest-destructuring/no-rest-destructuring.rule'
import * as noUnstableQueryMutationInDeps from './rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule'
import * as noUnstableDeps from './rules/no-unstable-deps/no-unstable-deps.rule'
import type { ESLintUtils } from '@typescript-eslint/utils'
import type { ExtraRuleDocs } from './types'

Expand All @@ -17,5 +17,5 @@ export const rules: Record<
[exhaustiveDeps.name]: exhaustiveDeps.rule,
[stableQueryClient.name]: stableQueryClient.rule,
[noRestDestructuring.name]: noRestDestructuring.rule,
[noUnstableQueryMutationInDeps.name]: noUnstableQueryMutationInDeps.rule,
[noUnstableDeps.name]: noUnstableDeps.rule,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { detectTanstackQueryImports } from '../../utils/detect-react-query-impor
import type { TSESTree } from '@typescript-eslint/utils'
import type { ExtraRuleDocs } from '../../types'

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

export const reactHookNames = ['useEffect', 'useCallback', 'useMemo']
export const useQueryHookNames = [
Expand Down

0 comments on commit ce75bc4

Please sign in to comment.