@tanstack/eslint-plugin-query 5.0.0-beta.0 → 5.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/build/legacy/__tests__/configs.test.cjs +21 -0
  2. package/build/legacy/__tests__/configs.test.cjs.map +1 -0
  3. package/build/legacy/__tests__/configs.test.d.cts +2 -0
  4. package/build/legacy/__tests__/configs.test.d.ts +2 -0
  5. package/build/legacy/__tests__/configs.test.js +19 -0
  6. package/build/legacy/__tests__/configs.test.js.map +1 -0
  7. package/build/legacy/__tests__/exhaustive-deps.test.cjs +722 -0
  8. package/build/legacy/__tests__/exhaustive-deps.test.cjs.map +1 -0
  9. package/build/legacy/__tests__/exhaustive-deps.test.d.cts +2 -0
  10. package/build/legacy/__tests__/exhaustive-deps.test.d.ts +2 -0
  11. package/build/legacy/__tests__/exhaustive-deps.test.js +720 -0
  12. package/build/legacy/__tests__/exhaustive-deps.test.js.map +1 -0
  13. package/build/legacy/configs.cjs +46 -0
  14. package/build/legacy/configs.cjs.map +1 -0
  15. package/build/legacy/configs.d.cts +8 -0
  16. package/build/legacy/configs.d.ts +8 -0
  17. package/build/legacy/configs.js +21 -0
  18. package/build/legacy/configs.js.map +1 -0
  19. package/build/legacy/index.d.cts +3 -14
  20. package/build/legacy/index.d.ts +3 -14
  21. package/build/legacy/rules/exhaustive-deps.rule.cjs +141 -0
  22. package/build/legacy/rules/exhaustive-deps.rule.cjs.map +1 -0
  23. package/build/legacy/rules/exhaustive-deps.rule.d.cts +6 -0
  24. package/build/legacy/rules/exhaustive-deps.rule.d.ts +6 -0
  25. package/build/legacy/rules/exhaustive-deps.rule.js +115 -0
  26. package/build/legacy/rules/exhaustive-deps.rule.js.map +1 -0
  27. package/build/legacy/rules/exhaustive-deps.utils.cjs +52 -0
  28. package/build/legacy/rules/exhaustive-deps.utils.cjs.map +1 -0
  29. package/build/legacy/rules/exhaustive-deps.utils.d.cts +12 -0
  30. package/build/legacy/rules/exhaustive-deps.utils.d.ts +12 -0
  31. package/build/legacy/rules/exhaustive-deps.utils.js +27 -0
  32. package/build/legacy/rules/exhaustive-deps.utils.js.map +1 -0
  33. package/build/legacy/rules.cjs +44 -0
  34. package/build/legacy/rules.cjs.map +1 -0
  35. package/build/legacy/rules.d.cts +7 -0
  36. package/build/legacy/rules.d.ts +7 -0
  37. package/build/legacy/rules.js +9 -0
  38. package/build/legacy/rules.js.map +1 -0
  39. package/build/legacy/utils/ast-utils.cjs +247 -0
  40. package/build/legacy/utils/ast-utils.cjs.map +1 -0
  41. package/build/legacy/utils/ast-utils.d.cts +41 -0
  42. package/build/legacy/utils/ast-utils.d.ts +41 -0
  43. package/build/legacy/utils/ast-utils.js +222 -0
  44. package/build/legacy/utils/ast-utils.js.map +1 -0
  45. package/build/legacy/utils/create-rule.cjs +39 -0
  46. package/build/legacy/utils/create-rule.cjs.map +1 -0
  47. package/build/legacy/utils/create-rule.d.cts +10 -0
  48. package/build/legacy/utils/create-rule.d.ts +10 -0
  49. package/build/legacy/utils/create-rule.js +14 -0
  50. package/build/legacy/utils/create-rule.js.map +1 -0
  51. package/build/legacy/utils/detect-react-query-imports.cjs +70 -0
  52. package/build/legacy/utils/detect-react-query-imports.cjs.map +1 -0
  53. package/build/legacy/utils/detect-react-query-imports.d.cts +12 -0
  54. package/build/legacy/utils/detect-react-query-imports.d.ts +12 -0
  55. package/build/legacy/utils/detect-react-query-imports.js +45 -0
  56. package/build/legacy/utils/detect-react-query-imports.js.map +1 -0
  57. package/build/legacy/utils/object-utils.cjs +33 -0
  58. package/build/legacy/utils/object-utils.cjs.map +1 -0
  59. package/build/legacy/utils/object-utils.d.cts +3 -0
  60. package/build/legacy/utils/object-utils.d.ts +3 -0
  61. package/build/legacy/utils/object-utils.js +8 -0
  62. package/build/legacy/utils/object-utils.js.map +1 -0
  63. package/build/legacy/utils/test-utils.cjs +36 -0
  64. package/build/legacy/utils/test-utils.cjs.map +1 -0
  65. package/build/legacy/utils/test-utils.d.cts +3 -0
  66. package/build/legacy/utils/test-utils.d.ts +3 -0
  67. package/build/legacy/utils/test-utils.js +11 -0
  68. package/build/legacy/utils/test-utils.js.map +1 -0
  69. package/build/legacy/utils/unique-by.cjs +33 -0
  70. package/build/legacy/utils/unique-by.cjs.map +1 -0
  71. package/build/legacy/utils/unique-by.d.cts +3 -0
  72. package/build/legacy/utils/unique-by.d.ts +3 -0
  73. package/build/legacy/utils/unique-by.js +8 -0
  74. package/build/legacy/utils/unique-by.js.map +1 -0
  75. package/package.json +2 -2
  76. package/src/{configs/index.test.ts → __tests__/configs.test.ts} +1 -1
  77. package/src/{rules/exhaustive-deps → __tests__}/exhaustive-deps.test.ts +2 -2
  78. package/src/{configs/index.ts → configs.ts} +1 -1
  79. package/src/rules/{exhaustive-deps/exhaustive-deps.rule.ts → exhaustive-deps.rule.ts} +3 -3
  80. package/src/rules/{exhaustive-deps/exhaustive-deps.utils.ts → exhaustive-deps.utils.ts} +1 -1
  81. package/src/rules.ts +5 -0
  82. package/src/rules/index.ts +0 -5
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/__tests__/exhaustive-deps.test.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { normalizeIndent } from '../utils/test-utils'\nimport { rule } from '../rules/exhaustive-deps.rule'\n\nconst ruleTester = new ESLintUtils.RuleTester({\n parser: '@typescript-eslint/parser',\n settings: {},\n})\n\nruleTester.run('exhaustive-deps', rule, {\n valid: [\n {\n name: 'should pass when deps are passed in array (react)',\n code: 'useQuery({ queryKey: [\"todos\"], queryFn: fetchTodos });',\n },\n {\n name: 'should pass when deps are passed in array (solid)',\n code: 'createQuery({ queryKey: [\"todos\"], queryFn: fetchTodos });',\n },\n {\n name: 'should pass when deps are passed in array',\n code: 'useQuery({ queryKey: [\"entity\", id], queryFn: () => api.getEntity(id) });',\n },\n {\n name: 'should pass when deps are passed in template literal',\n // eslint-disable-next-line no-template-curly-in-string\n code: 'useQuery({ queryKey: [`entity/${id}`], queryFn: () => api.getEntity(id) });',\n },\n {\n name: 'should not pass fetch',\n code: 'useQuery({ queryKey: [\"entity\", id], queryFn: () => fetch(id) });',\n },\n {\n name: 'should not pass axios.get',\n code: 'useQuery({ queryKey: [\"entity\", id], queryFn: () => axios.get(id) });',\n },\n {\n name: 'should not pass api.entity.get',\n code: 'useQuery({ queryKey: [\"entity\", id], queryFn: () => api.entity.get(id) });',\n },\n {\n name: 'should not pass api when is being used for calling a function',\n code: `\n import useApi from './useApi'\n\n const useFoo = () => {\n const api = useApi();\n return useQuery({\n queryKey: ['foo'],\n queryFn: () => api.fetchFoo(),\n })\n }\n `,\n },\n {\n name: 'should pass props.src',\n code: `\n function MyComponent(props) {\n useQuery({ queryKey: [\"entity\", props.src], queryFn: () => api.entity.get(props.src) });\n }\n `,\n },\n {\n name: 'identify !!props.id (unary expression)',\n code: `\n function MyComponent(props) {\n useQuery({ queryKey: [\"entity\", !!props.id], queryFn: () => api.entity.get(props.id) });\n }\n `,\n },\n {\n name: 'identify props?.id (chain expression)',\n code: `\n function MyComponent(props) {\n useQuery({ queryKey: [\"entity\", props?.id], queryFn: () => api.entity.get(props?.id) });\n }\n `,\n },\n {\n name: 'identify props!.id (ts non null expression)',\n code: `\n function MyComponent(props) {\n useQuery({ queryKey: [\"entity\", props!.id], queryFn: () => api.entity.get(props!.id) });\n }\n `,\n },\n {\n name: 'should ignore keys from callback',\n code: `\n function MyComponent(props) {\n useQuery({\n queryKey: [\"foo\", dep1],\n queryFn: ({ queryKey: [, dep] }) => fetch(dep),\n });\n }\n `,\n },\n {\n name: 'should ignore type identifiers',\n code: `\n type Result = {};\n function MyComponent(props) {\n useQuery({\n queryKey: [\"foo\", dep],\n queryFn: () => api.get<Result>(dep),\n });\n }\n `,\n },\n {\n name: 'should add \"...args\" to deps',\n code: `\n function foo(...args) {}\n function useData(arg, ...args) {\n return useQuery({\n queryKey: ['foo', arg, ...args],\n queryFn: async () => foo([arg, ...args])\n });\n }\n `,\n },\n {\n name: 'should not add class to deps',\n code: `\n class Foo {}\n useQuery({ queryKey: ['foo'], queryFn: async () => new Foo() });\n `,\n },\n {\n name: 'should not add `undefined` to deps',\n code: `\n useQuery({\n queryKey: [],\n queryFn: async () => {\n if (undefined) {\n return null;\n }\n return 1\n },\n });\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep as first arg',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo(num),\n queryFn: () => Promise.resolve(num),\n })\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep in object',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo({ x: num }),\n queryFn: () => Promise.resolve(num),\n })\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep in object 2',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo({ num }),\n queryFn: () => Promise.resolve(num),\n })\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep in array',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo([num]),\n queryFn: () => Promise.resolve(num),\n })\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep in second arg',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo(1, num),\n queryFn: () => Promise.resolve(num),\n })\n `,\n },\n {\n name: 'should not fail when queryKey is a queryKeyFactory while having a dep is object prop',\n code: normalizeIndent`\n const fooQueryKeyFactory = {\n foo: () => ['foo'] as const,\n num: (num: number) => [...fooQueryKeyFactory.foo(), num] as const,\n }\n \n const useFoo = (obj: { num: number }) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo(obj.num),\n queryFn: () => Promise.resolve(obj.num),\n })\n `,\n },\n {\n name: 'should not treat new Error as missing dependency',\n code: normalizeIndent`\n useQuery({\n queryKey: ['foo'],\n queryFn: () => Promise.reject(new Error('1')),\n })\n `,\n },\n {\n name: 'should see id when there is a const assertion',\n code: normalizeIndent`\n const useX = (id: number) => {\n return useQuery({\n queryKey: ['foo', id] as const,\n queryFn: async () => id,\n })\n }\n `,\n },\n {\n name: 'should not fail if queryKey is having the whole object while queryFn uses some props of it',\n code: normalizeIndent`\n const state = { foo: 'foo', bar: 'bar' }\n \n useQuery({\n queryKey: ['state', state],\n queryFn: () => Promise.resolve({ foo: state.foo, bar: state.bar })\n })\n `,\n },\n {\n name: 'should not fail if queryKey does not include an internal dependency',\n code: normalizeIndent`\n useQuery({\n queryKey: [\"api\"],\n queryFn: async () => {\n const response = Promise.resolve([]);\n const data = await response.json();\n return data[0].name;\n },\n });\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react component, function declaration)',\n code: `\n const CONST_VAL = 1\n function MyComponent() {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react component, function expression)',\n code: `\n const CONST_VAL = 1\n const MyComponent = () => {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react component, anonymous function)',\n code: `\n const CONST_VAL = 1\n const MyComponent = function () {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (non react component/hook function)',\n code: `\n const CONST_VAL = 1\n function fn() {\n return {\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n }\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react hook, function declaration)',\n code: `\n const CONST_VAL = 1\n function useHook() {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react hook, function expression)',\n code: `\n const CONST_VAL = 1\n const useHook = () => {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore constants defined out of scope (react hook, anonymous function)',\n code: `\n const CONST_VAL = 1\n const useHook = function () {\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => CONST_VAL\n });\n }\n `,\n },\n {\n name: 'should ignore references of the queryClient',\n code: `\n const CONST_VAL = 1\n function useHook() {\n const queryClient = useQueryClient()\n const kueryKlient = useQueryClient()\n useQuery({\n queryKey: [\"foo\"],\n queryFn: () => {\n doSomething(queryClient)\n queryClient.invalidateQueries()\n doSomethingSus(kueryKlient)\n }\n });\n }\n `,\n },\n ],\n invalid: [\n {\n name: 'should fail when deps are missing in query factory',\n code: normalizeIndent`\n const todoQueries = {\n list: () => ({ queryKey: ['entity'], queryFn: fetchEntities }),\n detail: (id) => ({ queryKey: ['entity'], queryFn: () => fetchEntity(id) })\n }\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'id' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: { result: \"['entity', id]\" },\n output: normalizeIndent`\n const todoQueries = {\n list: () => ({ queryKey: ['entity'], queryFn: fetchEntities }),\n detail: (id) => ({ queryKey: ['entity', id], queryFn: () => fetchEntity(id) })\n }\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when no deps are passed (react)',\n code: normalizeIndent`\n const id = 1;\n useQuery({ queryKey: [\"entity\"], queryFn: () => api.getEntity(id) });\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'id' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: { result: '[\"entity\", id]' },\n output: normalizeIndent`\n const id = 1;\n useQuery({ queryKey: [\"entity\", id], queryFn: () => api.getEntity(id) });\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when no deps are passed (solid)',\n code: normalizeIndent`\n const id = 1;\n createQuery({ queryKey: [\"entity\"], queryFn: () => api.getEntity(id) });\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'id' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: { result: '[\"entity\", id]' },\n output: normalizeIndent`\n const id = 1;\n createQuery({ queryKey: [\"entity\", id], queryFn: () => api.getEntity(id) });\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when deps are passed incorrectly',\n code: normalizeIndent`\n const id = 1;\n useQuery({ queryKey: [\"entity/\\${id}\"], queryFn: () => api.getEntity(id) });\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'id' },\n suggestions: [\n {\n messageId: 'fixTo',\n // eslint-disable-next-line no-template-curly-in-string\n data: { result: '[\"entity/${id}\", id]' },\n output: normalizeIndent`\n const id = 1;\n useQuery({ queryKey: [\"entity/\\${id}\", id], queryFn: () => api.getEntity(id) });\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should pass missing dep while key has a template literal',\n code: normalizeIndent`\n const a = 1;\n const b = 2;\n useQuery({ queryKey: [\\`entity/\\${a}\\`], queryFn: () => api.getEntity(a, b) });\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'b' },\n suggestions: [\n {\n messageId: 'fixTo',\n // eslint-disable-next-line no-template-curly-in-string\n data: { result: '[`entity/${a}`, b]' },\n output: normalizeIndent`\n const a = 1;\n const b = 2;\n useQuery({ queryKey: [\\`entity/\\${a}\\`, b], queryFn: () => api.getEntity(a, b) });\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when dep exists inside setter and missing in queryKey',\n code: normalizeIndent`\n const [id] = React.useState(1);\n useQuery({\n queryKey: [\"entity\"],\n queryFn: () => {\n const { data } = axios.get(\\`.../\\${id}\\`);\n return data;\n }\n });\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'id' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: { result: '[\"entity\", id]' },\n output: normalizeIndent`\n const [id] = React.useState(1);\n useQuery({\n queryKey: [\"entity\", id],\n queryFn: () => {\n const { data } = axios.get(\\`.../\\${id}\\`);\n return data;\n }\n });\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when dep does not exist while having a complex queryKey',\n code: normalizeIndent`\n const todoQueries = {\n key: (a, b, c, d, e) => ({\n queryKey: [\"entity\", a, [b], { c }, 1, true],\n queryFn: () => api.getEntity(a, b, c, d, e)\n })\n }\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'd, e' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: { result: '[\"entity\", a, [b], { c }, 1, true, d, e]' },\n output: normalizeIndent`\n const todoQueries = {\n key: (a, b, c, d, e) => ({\n queryKey: [\"entity\", a, [b], { c }, 1, true, d, e],\n queryFn: () => api.getEntity(a, b, c, d, e)\n })\n }\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when dep does not exist while having a complex queryKey #2',\n code: normalizeIndent`\n const todoQueries = {\n key: (dep1, dep2, dep3, dep4, dep5, dep6, dep7, dep8) => ({\n queryKey: ['foo', {dep1, dep2: dep2, bar: dep3, baz: [dep4, dep5]}, [dep6, dep7]],\n queryFn: () => api.getEntity(dep1, dep2, dep3, dep4, dep5, dep6, dep7, dep8),\n }),\n };\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'dep8' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: {\n result:\n \"['foo', {dep1, dep2: dep2, bar: dep3, baz: [dep4, dep5]}, [dep6, dep7], dep8]\",\n },\n output: normalizeIndent`\n const todoQueries = {\n key: (dep1, dep2, dep3, dep4, dep5, dep6, dep7, dep8) => ({\n queryKey: ['foo', {dep1, dep2: dep2, bar: dep3, baz: [dep4, dep5]}, [dep6, dep7], dep8],\n queryFn: () => api.getEntity(dep1, dep2, dep3, dep4, dep5, dep6, dep7, dep8),\n }),\n };\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when two deps that depend on each other are missing',\n code: normalizeIndent`\n function Component({ map, key }) {\n useQuery({ queryKey: [\"key\"], queryFn: () => api.get(map[key]) });\n }\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'map[key]' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: {\n result: '[\"key\", map[key]]',\n },\n output: normalizeIndent`\n function Component({ map, key }) {\n useQuery({ queryKey: [\"key\", map[key]], queryFn: () => api.get(map[key]) });\n }\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when a queryKey is a reference of an array expression with a missing dep',\n code: normalizeIndent`\n const x = 5;\n const queryKey = ['foo']\n useQuery({ queryKey, queryFn: () => x })\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'x' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: {\n result: \"['foo', x]\",\n },\n output: normalizeIndent`\n const x = 5;\n const queryKey = ['foo', x]\n useQuery({ queryKey, queryFn: () => x })\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when a queryKey is a reference of an array expression with a missing dep',\n code: normalizeIndent`\n const x = 5;\n const queryKey = ['foo']\n useQuery({ queryKey, queryFn: () => x })\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'x' },\n suggestions: [\n {\n messageId: 'fixTo',\n data: {\n result: \"['foo', x]\",\n },\n output: normalizeIndent`\n const x = 5;\n const queryKey = ['foo', x]\n useQuery({ queryKey, queryFn: () => x })\n `,\n },\n ],\n },\n ],\n },\n {\n name: 'should fail when queryKey is a queryKeyFactory while having missing dep',\n code: normalizeIndent`\n const fooQueryKeyFactory = { foo: () => ['foo'] as const }\n\n const useFoo = (num: number) =>\n useQuery({\n queryKey: fooQueryKeyFactory.foo(),\n queryFn: () => Promise.resolve(num),\n })\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'num' },\n },\n ],\n },\n {\n name: 'should fail if queryFn is using multiple object props when only one of them is in the queryKey',\n code: normalizeIndent`\n const state = { foo: 'foo', bar: 'bar' }\n \n useQuery({\n queryKey: ['state', state.foo],\n queryFn: () => Promise.resolve({ foo: state.foo, bar: state.bar })\n })\n `,\n errors: [\n {\n messageId: 'missingDeps',\n data: { deps: 'state.bar' },\n },\n ],\n },\n ],\n})\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAErB,IAAM,aAAa,IAAI,YAAY,WAAW;AAAA,EAC5C,QAAQ;AAAA,EACR,UAAU,CAAC;AACb,CAAC;AAED,WAAW,IAAI,mBAAmB,MAAM;AAAA,EACtC,OAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA;AAAA,MAEN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN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AA,gBACJ,QAAQ;AAAA,cACV;AAAA,cACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,YAKV;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,MAKN,QAAQ;AAAA,QACN;AAAA,UACE,WAAW;AAAA,UACX,MAAM,EAAE,MAAM,IAAI;AAAA,UAClB,aAAa;AAAA,YACX;AAAA,cACE,WAAW;AAAA,cACX,MAAM;AAAA,gBACJ,QAAQ;AAAA,cACV;AAAA,cACA,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,YAKV;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASN,QAAQ;AAAA,QACN;AAAA,UACE,WAAW;AAAA,UACX,MAAM,EAAE,MAAM,MAAM;AAAA,QACtB;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQN,QAAQ;AAAA,QACN;AAAA,UACE,WAAW;AAAA,UACX,MAAM,EAAE,MAAM,YAAY;AAAA,QAC5B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/configs.ts
21
+ var configs_exports = {};
22
+ __export(configs_exports, {
23
+ configs: () => configs
24
+ });
25
+ module.exports = __toCommonJS(configs_exports);
26
+ var import_rules = require("./rules.cjs");
27
+ function generateRecommendedConfig(allRules) {
28
+ return Object.entries(allRules).reduce((memo, [name, rule]) => {
29
+ const { recommended } = rule.meta.docs || {};
30
+ return {
31
+ ...memo,
32
+ ...recommended ? { [`@tanstack/query/${name}`]: recommended } : {}
33
+ };
34
+ }, {});
35
+ }
36
+ var configs = {
37
+ recommended: {
38
+ plugins: ["@tanstack/eslint-plugin-query"],
39
+ rules: generateRecommendedConfig(import_rules.rules)
40
+ }
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ configs
45
+ });
46
+ //# sourceMappingURL=configs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<string, TSESLint.RuleModule<any, any>>,\n) {\n return Object.entries(allRules).reduce((memo, [name, rule]) => {\n const { recommended } = rule.meta.docs || {}\n\n return {\n ...memo,\n ...(recommended ? { [`@tanstack/query/${name}`]: recommended } : {}),\n }\n }, {} as Record<string, 'strict' | 'error' | 'warn'>)\n}\n\nexport const configs = {\n recommended: {\n plugins: ['@tanstack/eslint-plugin-query'],\n rules: generateRecommendedConfig(rules),\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAGtB,SAAS,0BACP,UACA;AACA,SAAO,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM;AAC7D,UAAM,EAAE,YAAY,IAAI,KAAK,KAAK,QAAQ,CAAC;AAE3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,cAAc,EAAE,CAAC,mBAAmB,IAAI,EAAE,GAAG,YAAY,IAAI,CAAC;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,CAAgD;AACtD;AAEO,IAAM,UAAU;AAAA,EACrB,aAAa;AAAA,IACX,SAAS,CAAC,+BAA+B;AAAA,IACzC,OAAO,0BAA0B,kBAAK;AAAA,EACxC;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ declare const configs: {
2
+ recommended: {
3
+ plugins: string[];
4
+ rules: Record<string, "strict" | "error" | "warn">;
5
+ };
6
+ };
7
+
8
+ export { configs };
@@ -0,0 +1,8 @@
1
+ declare const configs: {
2
+ recommended: {
3
+ plugins: string[];
4
+ rules: Record<string, "strict" | "error" | "warn">;
5
+ };
6
+ };
7
+
8
+ export { configs };
@@ -0,0 +1,21 @@
1
+ // src/configs.ts
2
+ import { rules } from "./rules.js";
3
+ function generateRecommendedConfig(allRules) {
4
+ return Object.entries(allRules).reduce((memo, [name, rule]) => {
5
+ const { recommended } = rule.meta.docs || {};
6
+ return {
7
+ ...memo,
8
+ ...recommended ? { [`@tanstack/query/${name}`]: recommended } : {}
9
+ };
10
+ }, {});
11
+ }
12
+ var configs = {
13
+ recommended: {
14
+ plugins: ["@tanstack/eslint-plugin-query"],
15
+ rules: generateRecommendedConfig(rules)
16
+ }
17
+ };
18
+ export {
19
+ configs
20
+ };
21
+ //# sourceMappingURL=configs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<string, TSESLint.RuleModule<any, any>>,\n) {\n return Object.entries(allRules).reduce((memo, [name, rule]) => {\n const { recommended } = rule.meta.docs || {}\n\n return {\n ...memo,\n ...(recommended ? { [`@tanstack/query/${name}`]: recommended } : {}),\n }\n }, {} as Record<string, 'strict' | 'error' | 'warn'>)\n}\n\nexport const configs = {\n recommended: {\n plugins: ['@tanstack/eslint-plugin-query'],\n rules: generateRecommendedConfig(rules),\n },\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAGtB,SAAS,0BACP,UACA;AACA,SAAO,OAAO,QAAQ,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM;AAC7D,UAAM,EAAE,YAAY,IAAI,KAAK,KAAK,QAAQ,CAAC;AAE3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,cAAc,EAAE,CAAC,mBAAmB,IAAI,EAAE,GAAG,YAAY,IAAI,CAAC;AAAA,IACpE;AAAA,EACF,GAAG,CAAC,CAAgD;AACtD;AAEO,IAAM,UAAU;AAAA,EACrB,aAAa;AAAA,IACX,SAAS,CAAC,+BAA+B;AAAA,IACzC,OAAO,0BAA0B,KAAK;AAAA,EACxC;AACF;","names":[]}
@@ -1,14 +1,3 @@
1
- import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
2
-
3
- declare const configs: {
4
- recommended: {
5
- plugins: string[];
6
- rules: Record<string, "error" | "strict" | "warn">;
7
- };
8
- };
9
-
10
- declare const rules: {
11
- "exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
12
- };
13
-
14
- export { configs, rules };
1
+ export { configs } from './configs.cjs';
2
+ export { rules } from './rules.cjs';
3
+ import '@typescript-eslint/utils/dist/ts-eslint/Rule';
@@ -1,14 +1,3 @@
1
- import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
2
-
3
- declare const configs: {
4
- recommended: {
5
- plugins: string[];
6
- rules: Record<string, "error" | "strict" | "warn">;
7
- };
8
- };
9
-
10
- declare const rules: {
11
- "exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
12
- };
13
-
14
- export { configs, rules };
1
+ export { configs } from './configs.js';
2
+ export { rules } from './rules.js';
3
+ import '@typescript-eslint/utils/dist/ts-eslint/Rule';
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/rules/exhaustive-deps.rule.ts
21
+ var exhaustive_deps_rule_exports = {};
22
+ __export(exhaustive_deps_rule_exports, {
23
+ name: () => name,
24
+ rule: () => rule
25
+ });
26
+ module.exports = __toCommonJS(exhaustive_deps_rule_exports);
27
+ var import_utils = require("@typescript-eslint/utils");
28
+ var import_ast_utils = require("../utils/ast-utils.cjs");
29
+ var import_create_rule = require("../utils/create-rule.cjs");
30
+ var import_unique_by = require("../utils/unique-by.cjs");
31
+ var import_exhaustive_deps = require("./exhaustive-deps.utils.cjs");
32
+ var QUERY_KEY = "queryKey";
33
+ var QUERY_FN = "queryFn";
34
+ var name = "exhaustive-deps";
35
+ var rule = (0, import_create_rule.createRule)({
36
+ name,
37
+ meta: {
38
+ type: "problem",
39
+ docs: {
40
+ description: "Exhaustive deps rule for useQuery",
41
+ recommended: "error"
42
+ },
43
+ messages: {
44
+ missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
45
+ fixTo: "Fix to {{result}}"
46
+ },
47
+ hasSuggestions: true,
48
+ fixable: "code",
49
+ schema: []
50
+ },
51
+ defaultOptions: [],
52
+ create(context) {
53
+ return {
54
+ Property(node) {
55
+ if (node.parent === void 0 || !import_ast_utils.ASTUtils.isObjectExpression(node.parent) || !import_ast_utils.ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
56
+ return;
57
+ }
58
+ const scopeManager = context.getSourceCode().scopeManager;
59
+ const queryKey = import_ast_utils.ASTUtils.findPropertyWithIdentifierKey(
60
+ node.parent.properties,
61
+ QUERY_KEY
62
+ );
63
+ const queryFn = import_ast_utils.ASTUtils.findPropertyWithIdentifierKey(
64
+ node.parent.properties,
65
+ QUERY_FN
66
+ );
67
+ if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || queryFn.value.type !== import_utils.AST_NODE_TYPES.ArrowFunctionExpression) {
68
+ return;
69
+ }
70
+ let queryKeyNode = queryKey.value;
71
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === import_utils.AST_NODE_TYPES.ArrayExpression) {
72
+ queryKeyNode = queryKeyNode.expression;
73
+ }
74
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.Identifier) {
75
+ const expression = import_ast_utils.ASTUtils.getReferencedExpressionByIdentifier({
76
+ context,
77
+ node: queryKeyNode
78
+ });
79
+ if ((expression == null ? void 0 : expression.type) === import_utils.AST_NODE_TYPES.ArrayExpression) {
80
+ queryKeyNode = expression;
81
+ }
82
+ }
83
+ const sourceCode = context.getSourceCode();
84
+ const queryKeyValue = queryKeyNode;
85
+ const externalRefs = import_ast_utils.ASTUtils.getExternalRefs({
86
+ scopeManager,
87
+ sourceCode,
88
+ node: queryFn.value
89
+ });
90
+ const relevantRefs = externalRefs.filter(
91
+ (reference) => import_exhaustive_deps.ExhaustiveDepsUtils.isRelevantReference({
92
+ context,
93
+ reference,
94
+ scopeManager
95
+ })
96
+ );
97
+ const existingKeys = import_ast_utils.ASTUtils.getNestedIdentifiers(queryKeyValue).map(
98
+ (identifier) => import_ast_utils.ASTUtils.mapKeyNodeToText(identifier, sourceCode)
99
+ );
100
+ const missingRefs = relevantRefs.map((ref) => ({
101
+ ref,
102
+ text: import_ast_utils.ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)
103
+ })).filter(({ ref, text }) => {
104
+ return !ref.isTypeReference && !import_ast_utils.ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(".")[0] ?? "");
105
+ }).map(({ ref, text }) => ({
106
+ identifier: ref.identifier,
107
+ text
108
+ }));
109
+ const uniqueMissingRefs = (0, import_unique_by.uniqueBy)(missingRefs, (x) => x.text);
110
+ if (uniqueMissingRefs.length > 0) {
111
+ const missingAsText = uniqueMissingRefs.map((ref) => import_ast_utils.ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)).join(", ");
112
+ const existingWithMissing = sourceCode.getText(queryKeyValue).replace(/\]$/, `, ${missingAsText}]`);
113
+ const suggestions = [];
114
+ if (queryKeyNode.type === import_utils.AST_NODE_TYPES.ArrayExpression) {
115
+ suggestions.push({
116
+ messageId: "fixTo",
117
+ data: { result: existingWithMissing },
118
+ fix(fixer) {
119
+ return fixer.replaceText(queryKeyValue, existingWithMissing);
120
+ }
121
+ });
122
+ }
123
+ context.report({
124
+ node,
125
+ messageId: "missingDeps",
126
+ data: {
127
+ deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
128
+ },
129
+ suggest: suggestions
130
+ });
131
+ }
132
+ }
133
+ };
134
+ }
135
+ });
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ name,
139
+ rule
140
+ });
141
+ //# sourceMappingURL=exhaustive-deps.rule.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport { createRule } from '../utils/create-rule'\nimport { uniqueBy } from '../utils/unique-by'\nimport { ExhaustiveDepsUtils } from './exhaustive-deps.utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;A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;AAAA,cACpC,IAAI,OAAO;AACT,uBAAO,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;AAAA,YACF,CAAC;AAAA,UACH;AAEA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,YACX,MAAM;AAAA,cACJ,MAAM,kBAAkB,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,KAAK,IAAI;AAAA,YAC1D;AAAA,YACA,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const name = "exhaustive-deps";
4
+ declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
5
+
6
+ export { name, rule };
@@ -0,0 +1,6 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const name = "exhaustive-deps";
4
+ declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
5
+
6
+ export { name, rule };
@@ -0,0 +1,115 @@
1
+ // src/rules/exhaustive-deps.rule.ts
2
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
+ import { ASTUtils } from "../utils/ast-utils.js";
4
+ import { createRule } from "../utils/create-rule.js";
5
+ import { uniqueBy } from "../utils/unique-by.js";
6
+ import { ExhaustiveDepsUtils } from "./exhaustive-deps.utils.js";
7
+ var QUERY_KEY = "queryKey";
8
+ var QUERY_FN = "queryFn";
9
+ var name = "exhaustive-deps";
10
+ var rule = createRule({
11
+ name,
12
+ meta: {
13
+ type: "problem",
14
+ docs: {
15
+ description: "Exhaustive deps rule for useQuery",
16
+ recommended: "error"
17
+ },
18
+ messages: {
19
+ missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
20
+ fixTo: "Fix to {{result}}"
21
+ },
22
+ hasSuggestions: true,
23
+ fixable: "code",
24
+ schema: []
25
+ },
26
+ defaultOptions: [],
27
+ create(context) {
28
+ return {
29
+ Property(node) {
30
+ if (node.parent === void 0 || !ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
31
+ return;
32
+ }
33
+ const scopeManager = context.getSourceCode().scopeManager;
34
+ const queryKey = ASTUtils.findPropertyWithIdentifierKey(
35
+ node.parent.properties,
36
+ QUERY_KEY
37
+ );
38
+ const queryFn = ASTUtils.findPropertyWithIdentifierKey(
39
+ node.parent.properties,
40
+ QUERY_FN
41
+ );
42
+ if (scopeManager === null || queryKey === void 0 || queryFn === void 0 || queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression) {
43
+ return;
44
+ }
45
+ let queryKeyNode = queryKey.value;
46
+ if (queryKeyNode.type === AST_NODE_TYPES.TSAsExpression && queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression) {
47
+ queryKeyNode = queryKeyNode.expression;
48
+ }
49
+ if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {
50
+ const expression = ASTUtils.getReferencedExpressionByIdentifier({
51
+ context,
52
+ node: queryKeyNode
53
+ });
54
+ if ((expression == null ? void 0 : expression.type) === AST_NODE_TYPES.ArrayExpression) {
55
+ queryKeyNode = expression;
56
+ }
57
+ }
58
+ const sourceCode = context.getSourceCode();
59
+ const queryKeyValue = queryKeyNode;
60
+ const externalRefs = ASTUtils.getExternalRefs({
61
+ scopeManager,
62
+ sourceCode,
63
+ node: queryFn.value
64
+ });
65
+ const relevantRefs = externalRefs.filter(
66
+ (reference) => ExhaustiveDepsUtils.isRelevantReference({
67
+ context,
68
+ reference,
69
+ scopeManager
70
+ })
71
+ );
72
+ const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(
73
+ (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode)
74
+ );
75
+ const missingRefs = relevantRefs.map((ref) => ({
76
+ ref,
77
+ text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)
78
+ })).filter(({ ref, text }) => {
79
+ return !ref.isTypeReference && !ASTUtils.isAncestorIsCallee(ref.identifier) && !existingKeys.some((existingKey) => existingKey === text) && !existingKeys.includes(text.split(".")[0] ?? "");
80
+ }).map(({ ref, text }) => ({
81
+ identifier: ref.identifier,
82
+ text
83
+ }));
84
+ const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text);
85
+ if (uniqueMissingRefs.length > 0) {
86
+ const missingAsText = uniqueMissingRefs.map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode)).join(", ");
87
+ const existingWithMissing = sourceCode.getText(queryKeyValue).replace(/\]$/, `, ${missingAsText}]`);
88
+ const suggestions = [];
89
+ if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {
90
+ suggestions.push({
91
+ messageId: "fixTo",
92
+ data: { result: existingWithMissing },
93
+ fix(fixer) {
94
+ return fixer.replaceText(queryKeyValue, existingWithMissing);
95
+ }
96
+ });
97
+ }
98
+ context.report({
99
+ node,
100
+ messageId: "missingDeps",
101
+ data: {
102
+ deps: uniqueMissingRefs.map((ref) => ref.text).join(", ")
103
+ },
104
+ suggest: suggestions
105
+ });
106
+ }
107
+ }
108
+ };
109
+ }
110
+ });
111
+ export {
112
+ name,
113
+ rule
114
+ };
115
+ //# sourceMappingURL=exhaustive-deps.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport { createRule } from '../utils/create-rule'\nimport { uniqueBy } from '../utils/unique-by'\nimport { ExhaustiveDepsUtils } from './exhaustive-deps.utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAGpC,IAAM,YAAY;AAClB,IAAM,WAAW;AAEV,IAAM,OAAO;AAEb,IAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,aAAa;AAAA,MACb,OAAO;AAAA,IACT;AAAA,IACA,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS;AACd,WAAO;AAAA,MACL,SAAS,MAAM;AACb,YACE,KAAK,WAAW,UAChB,CAA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ACzB,iBACE,CAAC,IAAI,mBACL,CAAC,SAAS,mBAAmB,IAAI,UAAU,KAC3C,CAAC,aAAa,KAAK,CAAC,gBAAgB,gBAAgB,IAAI,KACxD,CAAC,aAAa,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,EAAE;AAAA,QAEnD,CAAC,EACA,IAAI,CAAC,EAAE,KAAK,KAAK,OAAO;AAAA,UACvB,YAAY,IAAI;AAAA,UAChB;AAAA,QACF,EAAE;AAEJ,cAAM,oBAAoB,SAAS,aAAa,CAAC,MAAM,EAAE,IAAI;AAE7D,YAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAM,gBAAgB,kBACnB,IAAI,CAAC,QAAQ,SAAS,iBAAiB,IAAI,YAAY,UAAU,CAAC,EAClE,KAAK,IAAI;AAEZ,gBAAM,sBAAsB,WACzB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KAAK,aAAa,GAAG;AAEvC,gBAAM,cAAsD,CAAC;AAE7D,cAAI,aAAa,SAAS,eAAe,iBAAiB;AACxD,wBAAY,KAAK;AAAA,cACf,WAAW;AAAA,cACX,MAAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACT,uBAAO,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;AAAA,YACF,CAAC;AAAA,UACH;AAEA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,YACX,MAAM;AAAA,cACJ,MAAM,kBAAkB,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,KAAK,IAAI;AAAA,YAC1D;AAAA,YACA,SAAS;AAAA,UACX,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/rules/exhaustive-deps.utils.ts
21
+ var exhaustive_deps_utils_exports = {};
22
+ __export(exhaustive_deps_utils_exports, {
23
+ ExhaustiveDepsUtils: () => ExhaustiveDepsUtils
24
+ });
25
+ module.exports = __toCommonJS(exhaustive_deps_utils_exports);
26
+ var import_utils = require("@typescript-eslint/utils");
27
+ var import_ast_utils = require("../utils/ast-utils.cjs");
28
+ var ExhaustiveDepsUtils = {
29
+ isRelevantReference(params) {
30
+ var _a;
31
+ const { reference, scopeManager, context } = params;
32
+ const component = import_ast_utils.ASTUtils.getFunctionAncestor(context);
33
+ if (component !== void 0 && !import_ast_utils.ASTUtils.isDeclaredInNode({
34
+ scopeManager,
35
+ reference,
36
+ functionNode: component
37
+ })) {
38
+ return false;
39
+ }
40
+ return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== import_utils.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
41
+ },
42
+ isQueryClientReference(reference) {
43
+ var _a, _b, _c;
44
+ const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
45
+ return (declarator == null ? void 0 : declarator.type) === import_utils.AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === import_utils.AST_NODE_TYPES.CallExpression && declarator.init.callee.type === import_utils.AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
46
+ }
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ ExhaustiveDepsUtils
51
+ });
52
+ //# sourceMappingURL=exhaustive-deps.utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const ExhaustiveDepsUtils = {\n isRelevantReference(params: {\n context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { reference, scopeManager, context } = params\n const component = ASTUtils.getFunctionAncestor(context)\n\n if (\n component !== undefined &&\n !ASTUtils.isDeclaredInNode({\n scopeManager,\n reference,\n functionNode: component,\n })\n ) {\n return false\n }\n\n return (\n reference.identifier.name !== 'undefined' &&\n reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression &&\n !ExhaustiveDepsUtils.isQueryClientReference(reference)\n )\n },\n isQueryClientReference(reference: TSESLint.Scope.Reference) {\n const declarator = reference.resolved?.defs[0]?.node\n\n return (\n declarator?.type === AST_NODE_TYPES.VariableDeclarator &&\n declarator.init?.type === AST_NODE_TYPES.CallExpression &&\n declarator.init.callee.type === AST_NODE_TYPES.Identifier &&\n declarator.init.callee.name === 'useQueryClient'\n )\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,uBAAyB;AAGlB,IAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;AATL;AAUI,UAAM,EAAE,WAAW,cAAc,QAAQ,IAAI;AAC7C,UAAM,YAAY,0BAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAAC,0BAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAChB,CAAC,GACD;AACA,aAAO;AAAA,IACT;AAEA,WACE,UAAU,WAAW,SAAS,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAAS,4BAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;AA9B9D;AA+BI,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAAS,4BAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAAS,4BAAe,kBACzC,WAAW,KAAK,OAAO,SAAS,4BAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const ExhaustiveDepsUtils: {
4
+ isRelevantReference(params: {
5
+ context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>;
6
+ reference: TSESLint.Scope.Reference;
7
+ scopeManager: TSESLint.Scope.ScopeManager;
8
+ }): boolean;
9
+ isQueryClientReference(reference: TSESLint.Scope.Reference): boolean;
10
+ };
11
+
12
+ export { ExhaustiveDepsUtils };
@@ -0,0 +1,12 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const ExhaustiveDepsUtils: {
4
+ isRelevantReference(params: {
5
+ context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>;
6
+ reference: TSESLint.Scope.Reference;
7
+ scopeManager: TSESLint.Scope.ScopeManager;
8
+ }): boolean;
9
+ isQueryClientReference(reference: TSESLint.Scope.Reference): boolean;
10
+ };
11
+
12
+ export { ExhaustiveDepsUtils };
@@ -0,0 +1,27 @@
1
+ // src/rules/exhaustive-deps.utils.ts
2
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
+ import { ASTUtils } from "../utils/ast-utils.js";
4
+ var ExhaustiveDepsUtils = {
5
+ isRelevantReference(params) {
6
+ var _a;
7
+ const { reference, scopeManager, context } = params;
8
+ const component = ASTUtils.getFunctionAncestor(context);
9
+ if (component !== void 0 && !ASTUtils.isDeclaredInNode({
10
+ scopeManager,
11
+ reference,
12
+ functionNode: component
13
+ })) {
14
+ return false;
15
+ }
16
+ return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
17
+ },
18
+ isQueryClientReference(reference) {
19
+ var _a, _b, _c;
20
+ const declarator = (_b = (_a = reference.resolved) == null ? void 0 : _a.defs[0]) == null ? void 0 : _b.node;
21
+ return (declarator == null ? void 0 : declarator.type) === AST_NODE_TYPES.VariableDeclarator && ((_c = declarator.init) == null ? void 0 : _c.type) === AST_NODE_TYPES.CallExpression && declarator.init.callee.type === AST_NODE_TYPES.Identifier && declarator.init.callee.name === "useQueryClient";
22
+ }
23
+ };
24
+ export {
25
+ ExhaustiveDepsUtils
26
+ };
27
+ //# sourceMappingURL=exhaustive-deps.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/rules/exhaustive-deps.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../utils/ast-utils'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const ExhaustiveDepsUtils = {\n isRelevantReference(params: {\n context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { reference, scopeManager, context } = params\n const component = ASTUtils.getFunctionAncestor(context)\n\n if (\n component !== undefined &&\n !ASTUtils.isDeclaredInNode({\n scopeManager,\n reference,\n functionNode: component,\n })\n ) {\n return false\n }\n\n return (\n reference.identifier.name !== 'undefined' &&\n reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression &&\n !ExhaustiveDepsUtils.isQueryClientReference(reference)\n )\n },\n isQueryClientReference(reference: TSESLint.Scope.Reference) {\n const declarator = reference.resolved?.defs[0]?.node\n\n return (\n declarator?.type === AST_NODE_TYPES.VariableDeclarator &&\n declarator.init?.type === AST_NODE_TYPES.CallExpression &&\n declarator.init.callee.type === AST_NODE_TYPES.Identifier &&\n declarator.init.callee.name === 'useQueryClient'\n )\n },\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AAGlB,IAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;AATL;AAUI,UAAM,EAAE,WAAW,cAAc,QAAQ,IAAI;AAC7C,UAAM,YAAY,SAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAAC,SAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAChB,CAAC,GACD;AACA,aAAO;AAAA,IACT;AAEA,WACE,UAAU,WAAW,SAAS,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAAS,eAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;AA9B9D;AA+BI,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAAS,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAAS,eAAe,kBACzC,WAAW,KAAK,OAAO,SAAS,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;","names":[]}