From ce75bc481a031e9550d39f8ef581512a0901e05b Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Mon, 19 Aug 2024 20:46:15 +0200 Subject: [PATCH] rename rule to "no-unstable-deps" --- docs/config.json | 4 ++-- docs/eslint/eslint-plugin-query.md | 2 +- ...e-query-mutation-in-deps.md => no-unstable-deps.md} | 6 +++--- ...tation-in-deps.test.ts => no-unstable-deps.test.ts} | 10 +++++++--- packages/eslint-plugin-query/src/index.ts | 4 ++-- packages/eslint-plugin-query/src/rules.ts | 4 ++-- .../no-unstable-deps.rule.ts} | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) rename docs/eslint/{no-unstable-query-mutation-in-deps.md => no-unstable-deps.md} (87%) rename packages/eslint-plugin-query/src/__tests__/{no-unstable-query-mutation-in-deps.test.ts => no-unstable-deps.test.ts} (94%) rename packages/eslint-plugin-query/src/rules/{no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule.ts => no-unstable-deps/no-unstable-deps.rule.ts} (98%) diff --git a/docs/config.json b/docs/config.json index 87a770bf91f..89eb47fd2a9 100644 --- a/docs/config.json +++ b/docs/config.json @@ -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" } ] }, diff --git a/docs/eslint/eslint-plugin-query.md b/docs/eslint/eslint-plugin-query.md index 377220a82a5..5c5ed684282 100644 --- a/docs/eslint/eslint-plugin-query.md +++ b/docs/eslint/eslint-plugin-query.md @@ -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) diff --git a/docs/eslint/no-unstable-query-mutation-in-deps.md b/docs/eslint/no-unstable-deps.md similarity index 87% rename from docs/eslint/no-unstable-query-mutation-in-deps.md rename to docs/eslint/no-unstable-deps.md index d5ccae1ca77..529f82def67 100644 --- a/docs/eslint/no-unstable-query-mutation-in-deps.md +++ b/docs/eslint/no-unstable-deps.md @@ -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 --- @@ -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' @@ -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' diff --git a/packages/eslint-plugin-query/src/__tests__/no-unstable-query-mutation-in-deps.test.ts b/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts similarity index 94% rename from packages/eslint-plugin-query/src/__tests__/no-unstable-query-mutation-in-deps.test.ts rename to packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts index 82b183abb26..470e60ffc34 100644 --- a/packages/eslint-plugin-query/src/__tests__/no-unstable-query-mutation-in-deps.test.ts +++ b/packages/eslint-plugin-query/src/__tests__/no-unstable-deps.test.ts @@ -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', @@ -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 `, @@ -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, diff --git a/packages/eslint-plugin-query/src/index.ts b/packages/eslint-plugin-query/src/index.ts index 0770e2cecaa..f70ccf7a88f 100644 --- a/packages/eslint-plugin-query/src/index.ts +++ b/packages/eslint-plugin-query/src/index.ts @@ -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': [ @@ -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', }, }, ], diff --git a/packages/eslint-plugin-query/src/rules.ts b/packages/eslint-plugin-query/src/rules.ts index 279760c65f6..9bc18ae9eac 100644 --- a/packages/eslint-plugin-query/src/rules.ts +++ b/packages/eslint-plugin-query/src/rules.ts @@ -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' @@ -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, } diff --git a/packages/eslint-plugin-query/src/rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule.ts b/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts similarity index 98% rename from packages/eslint-plugin-query/src/rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule.ts rename to packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts index de36ff0cf27..0d27bb2a267 100644 --- a/packages/eslint-plugin-query/src/rules/no-unstable-query-mutation-in-deps/no-unstable-query-mutation-in-deps.rule.ts +++ b/packages/eslint-plugin-query/src/rules/no-unstable-deps/no-unstable-deps.rule.ts @@ -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 = [