@tanstack/eslint-plugin-query 5.17.1 → 5.17.20

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 (169) hide show
  1. package/dist/cjs/configs.cjs +23 -0
  2. package/dist/cjs/configs.cjs.map +1 -0
  3. package/dist/cjs/configs.d.cts +6 -0
  4. package/dist/cjs/index.cjs +7 -0
  5. package/dist/cjs/index.cjs.map +1 -0
  6. package/dist/cjs/index.d.cts +2 -0
  7. package/dist/cjs/rules/exhaustive-deps.rule.cjs +114 -0
  8. package/dist/cjs/rules/exhaustive-deps.rule.cjs.map +1 -0
  9. package/dist/cjs/rules/exhaustive-deps.rule.d.cts +3 -0
  10. package/dist/cjs/rules/exhaustive-deps.utils.cjs +26 -0
  11. package/dist/cjs/rules/exhaustive-deps.utils.cjs.map +1 -0
  12. package/{build/legacy → dist/cjs}/rules/exhaustive-deps.utils.d.cts +2 -5
  13. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs +60 -0
  14. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs.map +1 -0
  15. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.cts +2 -0
  16. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.test.d.cts +1 -0
  17. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs +13 -0
  18. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs.map +1 -0
  19. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.cts +4 -0
  20. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs +66 -0
  21. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs.map +1 -0
  22. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.d.cts +3 -0
  23. package/dist/cjs/rules/stable-query-client/stable-query-client.test.d.cts +1 -0
  24. package/dist/cjs/rules.cjs +12 -0
  25. package/dist/cjs/rules.cjs.map +1 -0
  26. package/dist/cjs/rules.d.cts +5 -0
  27. package/{build/legacy → dist/cjs}/utils/ast-utils.cjs +31 -57
  28. package/dist/cjs/utils/ast-utils.cjs.map +1 -0
  29. package/{build/legacy → dist/cjs}/utils/ast-utils.d.cts +4 -6
  30. package/dist/cjs/utils/create-rule.cjs +13 -0
  31. package/dist/cjs/utils/create-rule.cjs.map +1 -0
  32. package/dist/cjs/utils/create-rule.d.cts +7 -0
  33. package/{build/legacy → dist/cjs}/utils/detect-react-query-imports.cjs +6 -32
  34. package/dist/cjs/utils/detect-react-query-imports.cjs.map +1 -0
  35. package/{build/legacy → dist/cjs}/utils/detect-react-query-imports.d.cts +5 -6
  36. package/dist/cjs/utils/test-utils.d.cts +1 -0
  37. package/dist/cjs/utils/unique-by.cjs +7 -0
  38. package/dist/cjs/utils/unique-by.cjs.map +1 -0
  39. package/dist/cjs/utils/unique-by.d.cts +1 -0
  40. package/dist/esm/configs.d.ts +6 -0
  41. package/{build/legacy → dist/esm}/configs.js +2 -3
  42. package/dist/esm/configs.js.map +1 -0
  43. package/dist/esm/index.d.ts +2 -0
  44. package/{build/legacy → dist/esm}/index.js +1 -2
  45. package/dist/esm/index.js.map +1 -0
  46. package/dist/esm/rules/exhaustive-deps.rule.d.ts +3 -0
  47. package/{build/legacy → dist/esm}/rules/exhaustive-deps.rule.js +5 -6
  48. package/dist/esm/rules/exhaustive-deps.rule.js.map +1 -0
  49. package/{build/legacy → dist/esm}/rules/exhaustive-deps.utils.d.ts +2 -5
  50. package/{build/legacy → dist/esm}/rules/exhaustive-deps.utils.js +2 -3
  51. package/dist/esm/rules/exhaustive-deps.utils.js.map +1 -0
  52. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.ts +2 -0
  53. package/{build/legacy → dist/esm}/rules/no-rest-desctructuring/no-rest-destructuring.rule.js +4 -5
  54. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.js.map +1 -0
  55. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.test.d.ts +1 -0
  56. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.ts +4 -0
  57. package/{build/legacy → dist/esm}/rules/no-rest-desctructuring/no-rest-destructuring.utils.js +2 -3
  58. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.utils.js.map +1 -0
  59. package/dist/esm/rules/stable-query-client/stable-query-client.rule.d.ts +3 -0
  60. package/{build/legacy → dist/esm}/rules/stable-query-client/stable-query-client.rule.js +3 -4
  61. package/dist/esm/rules/stable-query-client/stable-query-client.rule.js.map +1 -0
  62. package/dist/esm/rules/stable-query-client/stable-query-client.test.d.ts +1 -0
  63. package/dist/esm/rules.d.ts +5 -0
  64. package/dist/esm/rules.js +12 -0
  65. package/dist/esm/rules.js.map +1 -0
  66. package/{build/legacy → dist/esm}/utils/ast-utils.d.ts +4 -6
  67. package/{build/legacy → dist/esm}/utils/ast-utils.js +2 -3
  68. package/dist/esm/utils/ast-utils.js.map +1 -0
  69. package/dist/esm/utils/create-rule.d.ts +7 -0
  70. package/{build/legacy → dist/esm}/utils/create-rule.js +2 -3
  71. package/dist/esm/utils/create-rule.js.map +1 -0
  72. package/{build/legacy → dist/esm}/utils/detect-react-query-imports.d.ts +5 -6
  73. package/{build/legacy → dist/esm}/utils/detect-react-query-imports.js +1 -2
  74. package/dist/esm/utils/detect-react-query-imports.js.map +1 -0
  75. package/dist/esm/utils/test-utils.d.ts +1 -0
  76. package/dist/esm/utils/unique-by.d.ts +1 -0
  77. package/{build/legacy → dist/esm}/utils/unique-by.js +1 -2
  78. package/dist/esm/utils/unique-by.js.map +1 -0
  79. package/package.json +11 -12
  80. package/build/legacy/__tests__/configs.test.cjs +0 -24
  81. package/build/legacy/__tests__/configs.test.cjs.map +0 -1
  82. package/build/legacy/__tests__/configs.test.d.cts +0 -2
  83. package/build/legacy/__tests__/configs.test.d.ts +0 -2
  84. package/build/legacy/__tests__/configs.test.js +0 -22
  85. package/build/legacy/__tests__/configs.test.js.map +0 -1
  86. package/build/legacy/__tests__/exhaustive-deps.test.cjs +0 -722
  87. package/build/legacy/__tests__/exhaustive-deps.test.cjs.map +0 -1
  88. package/build/legacy/__tests__/exhaustive-deps.test.d.cts +0 -2
  89. package/build/legacy/__tests__/exhaustive-deps.test.d.ts +0 -2
  90. package/build/legacy/__tests__/exhaustive-deps.test.js +0 -720
  91. package/build/legacy/__tests__/exhaustive-deps.test.js.map +0 -1
  92. package/build/legacy/configs.cjs +0 -49
  93. package/build/legacy/configs.cjs.map +0 -1
  94. package/build/legacy/configs.d.cts +0 -8
  95. package/build/legacy/configs.d.ts +0 -8
  96. package/build/legacy/configs.js.map +0 -1
  97. package/build/legacy/index.cjs +0 -34
  98. package/build/legacy/index.cjs.map +0 -1
  99. package/build/legacy/index.d.cts +0 -3
  100. package/build/legacy/index.d.ts +0 -3
  101. package/build/legacy/index.js.map +0 -1
  102. package/build/legacy/rules/exhaustive-deps.rule.cjs +0 -141
  103. package/build/legacy/rules/exhaustive-deps.rule.cjs.map +0 -1
  104. package/build/legacy/rules/exhaustive-deps.rule.d.cts +0 -6
  105. package/build/legacy/rules/exhaustive-deps.rule.d.ts +0 -6
  106. package/build/legacy/rules/exhaustive-deps.rule.js.map +0 -1
  107. package/build/legacy/rules/exhaustive-deps.utils.cjs +0 -52
  108. package/build/legacy/rules/exhaustive-deps.utils.cjs.map +0 -1
  109. package/build/legacy/rules/exhaustive-deps.utils.js.map +0 -1
  110. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs +0 -87
  111. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs.map +0 -1
  112. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.cts +0 -6
  113. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.ts +0 -6
  114. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.js.map +0 -1
  115. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.cjs +0 -197
  116. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.cjs.map +0 -1
  117. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.d.cts +0 -2
  118. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.d.ts +0 -2
  119. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.js +0 -195
  120. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.js.map +0 -1
  121. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs +0 -39
  122. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs.map +0 -1
  123. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.cts +0 -7
  124. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.ts +0 -7
  125. package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.js.map +0 -1
  126. package/build/legacy/rules/stable-query-client/stable-query-client.rule.cjs +0 -93
  127. package/build/legacy/rules/stable-query-client/stable-query-client.rule.cjs.map +0 -1
  128. package/build/legacy/rules/stable-query-client/stable-query-client.rule.d.cts +0 -6
  129. package/build/legacy/rules/stable-query-client/stable-query-client.rule.d.ts +0 -6
  130. package/build/legacy/rules/stable-query-client/stable-query-client.rule.js.map +0 -1
  131. package/build/legacy/rules/stable-query-client/stable-query-client.test.cjs +0 -197
  132. package/build/legacy/rules/stable-query-client/stable-query-client.test.cjs.map +0 -1
  133. package/build/legacy/rules/stable-query-client/stable-query-client.test.d.cts +0 -2
  134. package/build/legacy/rules/stable-query-client/stable-query-client.test.d.ts +0 -2
  135. package/build/legacy/rules/stable-query-client/stable-query-client.test.js +0 -195
  136. package/build/legacy/rules/stable-query-client/stable-query-client.test.js.map +0 -1
  137. package/build/legacy/rules.cjs +0 -48
  138. package/build/legacy/rules.cjs.map +0 -1
  139. package/build/legacy/rules.d.cts +0 -9
  140. package/build/legacy/rules.d.ts +0 -9
  141. package/build/legacy/rules.js +0 -13
  142. package/build/legacy/rules.js.map +0 -1
  143. package/build/legacy/utils/ast-utils.cjs.map +0 -1
  144. package/build/legacy/utils/ast-utils.js.map +0 -1
  145. package/build/legacy/utils/create-rule.cjs +0 -39
  146. package/build/legacy/utils/create-rule.cjs.map +0 -1
  147. package/build/legacy/utils/create-rule.d.cts +0 -10
  148. package/build/legacy/utils/create-rule.d.ts +0 -10
  149. package/build/legacy/utils/create-rule.js.map +0 -1
  150. package/build/legacy/utils/detect-react-query-imports.cjs.map +0 -1
  151. package/build/legacy/utils/detect-react-query-imports.js.map +0 -1
  152. package/build/legacy/utils/object-utils.cjs +0 -33
  153. package/build/legacy/utils/object-utils.cjs.map +0 -1
  154. package/build/legacy/utils/object-utils.d.cts +0 -3
  155. package/build/legacy/utils/object-utils.d.ts +0 -3
  156. package/build/legacy/utils/object-utils.js +0 -8
  157. package/build/legacy/utils/object-utils.js.map +0 -1
  158. package/build/legacy/utils/test-utils.cjs +0 -36
  159. package/build/legacy/utils/test-utils.cjs.map +0 -1
  160. package/build/legacy/utils/test-utils.d.cts +0 -3
  161. package/build/legacy/utils/test-utils.d.ts +0 -3
  162. package/build/legacy/utils/test-utils.js +0 -11
  163. package/build/legacy/utils/test-utils.js.map +0 -1
  164. package/build/legacy/utils/unique-by.cjs +0 -33
  165. package/build/legacy/utils/unique-by.cjs.map +0 -1
  166. package/build/legacy/utils/unique-by.d.cts +0 -3
  167. package/build/legacy/utils/unique-by.d.ts +0 -3
  168. package/build/legacy/utils/unique-by.js.map +0 -1
  169. package/src/utils/object-utils.ts +0 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-utils.cjs","sources":["../../../src/utils/ast-utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { uniqueBy } from './unique-by'\nimport type { TSESLint, TSESTree } from '@typescript-eslint/utils'\nimport type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'\n\nexport const ASTUtils = {\n isNodeOfOneOf<T extends AST_NODE_TYPES>(\n node: TSESTree.Node,\n types: ReadonlyArray<T>,\n ): node is TSESTree.Node & { type: T } {\n return types.includes(node.type as T)\n },\n isIdentifier(node: TSESTree.Node): node is TSESTree.Identifier {\n return node.type === AST_NODE_TYPES.Identifier\n },\n isIdentifierWithName(\n node: TSESTree.Node,\n name: string,\n ): node is TSESTree.Identifier {\n return ASTUtils.isIdentifier(node) && node.name === name\n },\n isIdentifierWithOneOfNames<T extends Array<string>>(\n node: TSESTree.Node,\n name: T,\n ): node is TSESTree.Identifier & { name: T[number] } {\n return ASTUtils.isIdentifier(node) && name.includes(node.name)\n },\n isProperty(node: TSESTree.Node): node is TSESTree.Property {\n return node.type === AST_NODE_TYPES.Property\n },\n isObjectExpression(node: TSESTree.Node): node is TSESTree.ObjectExpression {\n return node.type === AST_NODE_TYPES.ObjectExpression\n },\n isPropertyWithIdentifierKey(\n node: TSESTree.Node,\n key: string,\n ): node is TSESTree.Property {\n return (\n ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key)\n )\n },\n findPropertyWithIdentifierKey(\n properties: Array<TSESTree.ObjectLiteralElement>,\n key: string,\n ): TSESTree.Property | undefined {\n return properties.find((x) =>\n ASTUtils.isPropertyWithIdentifierKey(x, key),\n ) as TSESTree.Property | undefined\n },\n getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier> {\n const identifiers: Array<TSESTree.Identifier> = []\n\n if (ASTUtils.isIdentifier(node)) {\n identifiers.push(node)\n }\n\n if ('arguments' in node) {\n node.arguments.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('elements' in node) {\n node.elements.forEach((x) => {\n if (x !== null) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n }\n })\n }\n\n if ('properties' in node) {\n node.properties.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('expressions' in node) {\n node.expressions.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if (node.type === AST_NODE_TYPES.Property) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.value))\n }\n\n if (node.type === AST_NODE_TYPES.SpreadElement) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.MemberExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.object))\n }\n\n if (node.type === AST_NODE_TYPES.UnaryExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.ChainExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n if (node.type === AST_NODE_TYPES.TSNonNullExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n return identifiers\n },\n isAncestorIsCallee(identifier: TSESTree.Node) {\n let previousNode = identifier\n let currentNode = identifier.parent\n\n while (currentNode !== undefined) {\n if (\n currentNode.type === AST_NODE_TYPES.CallExpression &&\n currentNode.callee === previousNode\n ) {\n return true\n }\n\n if (currentNode.type !== AST_NODE_TYPES.MemberExpression) {\n return false\n }\n\n previousNode = currentNode\n currentNode = currentNode.parent\n }\n\n return false\n },\n traverseUpOnly(\n identifier: TSESTree.Node,\n allowedNodeTypes: Array<AST_NODE_TYPES>,\n ): TSESTree.Node {\n const parent = identifier.parent\n\n if (parent !== undefined && allowedNodeTypes.includes(parent.type)) {\n return ASTUtils.traverseUpOnly(parent, allowedNodeTypes)\n }\n\n return identifier\n },\n isDeclaredInNode(params: {\n functionNode: TSESTree.Node\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { functionNode, reference, scopeManager } = params\n const scope = scopeManager.acquire(functionNode)\n\n if (scope === null) {\n return false\n }\n\n return scope.set.has(reference.identifier.name)\n },\n getExternalRefs(params: {\n scopeManager: TSESLint.Scope.ScopeManager\n sourceCode: Readonly<TSESLint.SourceCode>\n node: TSESTree.Node\n }): Array<TSESLint.Scope.Reference> {\n const { scopeManager, sourceCode, node } = params\n const scope = scopeManager.acquire(node)\n\n if (scope === null) {\n return []\n }\n\n const references = scope.references\n .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))\n .map((x) => {\n const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.Identifier,\n ])\n\n return {\n variable: x,\n node: referenceNode,\n text: sourceCode.getText(referenceNode),\n }\n })\n\n const localRefIds = new Set(\n [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])),\n )\n\n const externalRefs = references.filter(\n (x) => x.variable.resolved === null || !localRefIds.has(x.text),\n )\n\n return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable)\n },\n mapKeyNodeToText(\n node: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n ) {\n return sourceCode.getText(\n ASTUtils.traverseUpOnly(node, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.Identifier,\n ]),\n )\n },\n isValidReactComponentOrHookName(\n identifier: TSESTree.Identifier | null | undefined,\n ) {\n return (\n identifier !== null &&\n identifier !== undefined &&\n /^(use|[A-Z])/.test(identifier.name)\n )\n },\n getFunctionAncestor(\n context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>,\n ) {\n for (const ancestor of context.getAncestors()) {\n if (ancestor.type === AST_NODE_TYPES.FunctionDeclaration) {\n return ancestor\n }\n\n if (\n ancestor.parent?.type === AST_NODE_TYPES.VariableDeclarator &&\n ancestor.parent.id.type === AST_NODE_TYPES.Identifier &&\n ASTUtils.isNodeOfOneOf(ancestor, [\n AST_NODE_TYPES.FunctionDeclaration,\n AST_NODE_TYPES.FunctionExpression,\n AST_NODE_TYPES.ArrowFunctionExpression,\n ])\n ) {\n return ancestor\n }\n }\n\n return undefined\n },\n getReferencedExpressionByIdentifier(params: {\n node: TSESTree.Node\n context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>\n }) {\n const { node, context } = params\n\n const resolvedNode = context\n .getScope()\n .references.find((ref) => ref.identifier === node)?.resolved?.defs[0]\n ?.node\n\n if (resolvedNode?.type !== AST_NODE_TYPES.VariableDeclarator) {\n return null\n }\n\n return resolvedNode.init\n },\n getClosestVariableDeclarator(node: TSESTree.Node) {\n let currentNode: TSESTree.Node | undefined = node\n\n while (\n currentNode !== undefined &&\n currentNode.type !== AST_NODE_TYPES.Program\n ) {\n if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {\n return currentNode\n }\n\n currentNode = currentNode.parent\n }\n\n return undefined\n },\n getNestedReturnStatements(\n node: TSESTree.Node,\n ): Array<TSESTree.ReturnStatement> {\n const returnStatements: Array<TSESTree.ReturnStatement> = []\n\n if (node.type === AST_NODE_TYPES.ReturnStatement) {\n returnStatements.push(node)\n }\n\n if ('body' in node && node.body !== undefined && node.body !== null) {\n Array.isArray(node.body)\n ? node.body.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.body),\n )\n }\n\n if ('consequent' in node) {\n Array.isArray(node.consequent)\n ? node.consequent.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.consequent),\n )\n }\n\n if ('alternate' in node && node.alternate !== null) {\n Array.isArray(node.alternate)\n ? node.alternate.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.alternate),\n )\n }\n\n if ('cases' in node) {\n node.cases.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n }\n\n if ('block' in node) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block))\n }\n\n if ('handler' in node && node.handler !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler))\n }\n\n if ('finalizer' in node && node.finalizer !== null) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.finalizer),\n )\n }\n\n if (\n 'expression' in node &&\n node.expression !== true &&\n node.expression !== false\n ) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.expression),\n )\n }\n\n if ('test' in node && node.test !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test))\n }\n\n return returnStatements\n },\n}\n"],"names":["AST_NODE_TYPES","uniqueBy"],"mappings":";;;;AAKO,MAAM,WAAW;AAAA,EACtB,cACE,MACA,OACqC;AAC9B,WAAA,MAAM,SAAS,KAAK,IAAS;AAAA,EACtC;AAAA,EACA,aAAa,MAAkD;AACtD,WAAA,KAAK,SAASA,MAAe,eAAA;AAAA,EACtC;AAAA,EACA,qBACE,MACA,MAC6B;AAC7B,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS;AAAA,EACtD;AAAA,EACA,2BACE,MACA,MACmD;AACnD,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS,KAAK,IAAI;AAAA,EAC/D;AAAA,EACA,WAAW,MAAgD;AAClD,WAAA,KAAK,SAASA,MAAe,eAAA;AAAA,EACtC;AAAA,EACA,mBAAmB,MAAwD;AAClE,WAAA,KAAK,SAASA,MAAe,eAAA;AAAA,EACtC;AAAA,EACA,4BACE,MACA,KAC2B;AAEzB,WAAA,SAAS,WAAW,IAAI,KAAK,SAAS,qBAAqB,KAAK,KAAK,GAAG;AAAA,EAE5E;AAAA,EACA,8BACE,YACA,KAC+B;AAC/B,WAAO,WAAW;AAAA,MAAK,CAAC,MACtB,SAAS,4BAA4B,GAAG,GAAG;AAAA,IAAA;AAAA,EAE/C;AAAA,EACA,qBAAqB,MAAiD;AACpE,UAAM,cAA0C,CAAA;AAE5C,QAAA,SAAS,aAAa,IAAI,GAAG;AAC/B,kBAAY,KAAK,IAAI;AAAA,IACvB;AAEA,QAAI,eAAe,MAAM;AAClB,WAAA,UAAU,QAAQ,CAAC,MA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AK,SAAS;AAAA,MAAA;AAAA,IAE5D;AAEA,QAAI,WAAW,MAAM;AACd,WAAA,MAAM,QAAQ,CAAC,MAAM;AACxB,yBAAiB,KAAK,GAAG,SAAS,0BAA0B,CAAC,CAAC;AAAA,MAAA,CAC/D;AAAA,IACH;AAEA,QAAI,WAAW,MAAM;AACnB,uBAAiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,KAAK,CAAC;AAAA,IACzE;AAEA,QAAI,aAAa,QAAQ,KAAK,YAAY,MAAM;AAC9C,uBAAiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,OAAO,CAAC;AAAA,IAC3E;AAEA,QAAI,eAAe,QAAQ,KAAK,cAAc,MAAM;AACjC,uBAAA;AAAA,QACf,GAAG,SAAS,0BAA0B,KAAK,SAAS;AAAA,MAAA;AAAA,IAExD;AAEA,QACE,gBAAgB,QAChB,KAAK,eAAe,QACpB,KAAK,eAAe,OACpB;AACiB,uBAAA;AAAA,QACf,GAAG,SAAS,0BAA0B,KAAK,UAAU;AAAA,MAAA;AAAA,IAEzD;AAEA,QAAI,UAAU,QAAQ,KAAK,SAAS,MAAM;AACxC,uBAAiB,KAAK,GAAG,SAAS,0BAA0B,KAAK,IAAI,CAAC;AAAA,IACxE;AAEO,WAAA;AAAA,EACT;AACF;;"}
@@ -1,7 +1,7 @@
1
- import { AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils';
2
- import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
3
-
4
- declare const ASTUtils: {
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
3
+ import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
4
+ export declare const ASTUtils: {
5
5
  isNodeOfOneOf<T extends AST_NODE_TYPES>(node: TSESTree.Node, types: readonly T[]): node is TSESTree.Node & {
6
6
  type: T;
7
7
  };
@@ -37,5 +37,3 @@ declare const ASTUtils: {
37
37
  getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.VariableDeclarator | undefined;
38
38
  getNestedReturnStatements(node: TSESTree.Node): Array<TSESTree.ReturnStatement>;
39
39
  };
40
-
41
- export { ASTUtils };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("@typescript-eslint/utils");
4
+ const detectReactQueryImports = require("./detect-react-query-imports.cjs");
5
+ const getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
6
+ function createRule({ create, ...rest }) {
7
+ return utils.ESLintUtils.RuleCreator(getDocsUrl)({
8
+ ...rest,
9
+ create: detectReactQueryImports.detectTanstackQueryImports(create)
10
+ });
11
+ }
12
+ exports.createRule = createRule;
13
+ //# sourceMappingURL=create-rule.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-rule.cjs","sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/v4/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"names":["ESLintUtils","detectTanstackQueryImports"],"mappings":";;;;AAIA,MAAM,aAAa,CAAC,aAClB,6CAA6C,QAAQ;AAShD,SAAS,WAAW,EAAE,QAAQ,GAAG,QAAoB;AACnD,SAAAA,MAAA,YAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,QAAQC,mDAA2B,MAAM;AAAA,EAAA,CAC1C;AACH;;"}
@@ -0,0 +1,7 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import type { EnhancedCreate } from './detect-react-query-imports';
3
+ type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
4
+ create: EnhancedCreate;
5
+ };
6
+ export declare function createRule({ create, ...rest }: EslintRule): import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
7
+ export {};
@@ -1,29 +1,6 @@
1
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/utils/detect-react-query-imports.ts
21
- var detect_react_query_imports_exports = {};
22
- __export(detect_react_query_imports_exports, {
23
- detectTanstackQueryImports: () => detectTanstackQueryImports
24
- });
25
- module.exports = __toCommonJS(detect_react_query_imports_exports);
26
- var import_utils = require("@typescript-eslint/utils");
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("@typescript-eslint/utils");
27
4
  function detectTanstackQueryImports(create) {
28
5
  return (context, optionsWithDefault) => {
29
6
  const tanstackQueryImportSpecifiers = [];
@@ -31,7 +8,7 @@ function detectTanstackQueryImports(create) {
31
8
  isSpecificTanstackQueryImport(node, source) {
32
9
  return !!tanstackQueryImportSpecifiers.find((specifier) => {
33
10
  var _a;
34
- if (specifier.type === import_utils.TSESTree.AST_NODE_TYPES.ImportSpecifier && ((_a = specifier.parent) == null ? void 0 : _a.type) === import_utils.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
11
+ if (specifier.type === utils.TSESTree.AST_NODE_TYPES.ImportSpecifier && ((_a = specifier.parent) == null ? void 0 : _a.type) === utils.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
35
12
  return node.name === specifier.local.name;
36
13
  }
37
14
  return false;
@@ -39,7 +16,7 @@ function detectTanstackQueryImports(create) {
39
16
  },
40
17
  isTanstackQueryImport(node) {
41
18
  return !!tanstackQueryImportSpecifiers.find((specifier) => {
42
- if (specifier.type === import_utils.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
19
+ if (specifier.type === utils.TSESTree.AST_NODE_TYPES.ImportSpecifier) {
43
20
  return node.name === specifier.local.name;
44
21
  }
45
22
  return false;
@@ -73,8 +50,5 @@ function detectTanstackQueryImports(create) {
73
50
  return enhancedRuleInstructions;
74
51
  };
75
52
  }
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- detectTanstackQueryImports
79
- });
80
- //# sourceMappingURL=detect-react-query-imports.cjs.map
53
+ exports.detectTanstackQueryImports = detectTanstackQueryImports;
54
+ //# sourceMappingURL=detect-react-query-imports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-react-query-imports.cjs","sources":["../../../src/utils/detect-react-query-imports.ts"],"sourcesContent":["import { TSESTree } from '@typescript-eslint/utils'\nimport type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\ntype Create = Parameters<\n ReturnType<typeof ESLintUtils.RuleCreator>\n>[0]['create']\n\ntype Context = Parameters<Create>[0]\ntype Options = Parameters<Create>[1]\ntype Helpers = {\n isSpecificTanstackQueryImport: (\n node: TSESTree.Identifier,\n source: string,\n ) => boolean\n isTanstackQueryImport: (node: TSESTree.Identifier) => boolean\n}\n\nexport type EnhancedCreate = (\n context: Context,\n options: Options,\n helpers: Helpers,\n) => ReturnType<Create>\n\nexport function detectTanstackQueryImports(create: EnhancedCreate): Create {\n return (context, optionsWithDefault) => {\n const tanstackQueryImportSpecifiers: Array<TSESTree.ImportClause> = []\n\n const helpers: Helpers = {\n isSpecificTanstackQueryImport(node, source) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (\n specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&\n specifier.parent?.type ===\n TSESTree.AST_NODE_TYPES.ImportDeclaration &&\n specifier.parent.source.value === source\n ) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n isTanstackQueryImport(node) {\n return !!tanstackQueryImportSpecifiers.find((specifier) => {\n if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier) {\n return node.name === specifier.local.name\n }\n\n return false\n })\n },\n }\n\n const detectionInstructions: TSESLint.RuleListener = {\n ImportDeclaration(node) {\n if (\n node.specifiers.length > 0 &&\n node.importKind === 'value' &&\n node.source.value.startsWith('@tanstack/') &&\n node.source.value.endsWith('-query')\n ) {\n tanstackQueryImportSpecifiers.push(...node.specifiers)\n }\n },\n }\n\n // Call original rule definition\n const ruleInstructions = create(context, optionsWithDefault, helpers)\n const enhancedRuleInstructions: TSESLint.RuleListener = {}\n\n const allKeys = new Set(\n Object.keys(detectionInstructions).concat(Object.keys(ruleInstructions)),\n )\n\n // Iterate over ALL instructions keys so we can override original rule instructions\n // to prevent their execution if conditions to report errors are not met.\n allKeys.forEach((instruction) => {\n enhancedRuleInstructions[instruction] = (node) => {\n if (instruction in detectionInstructions) {\n detectionInstructions[instruction]?.(node)\n }\n\n // TODO: canReportErrors()\n if (ruleInstructions[instruction]) {\n return ruleInstructions[instruction]?.(node)\n }\n\n return undefined\n }\n })\n\n return enhancedRuleInstructions\n }\n}\n"],"names":["TSESTree"],"mappings":";;;AAuBO,SAAS,2BAA2B,QAAgC;AAClE,SAAA,CAAC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C;AAAA,QACzC;AAEO,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAEM,WAAA;AAAA,EAAA;AAEX;;"}
@@ -1,5 +1,5 @@
1
- import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
2
-
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import type { ESLintUtils } from '@typescript-eslint/utils';
3
3
  type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
4
4
  type Context = Parameters<Create>[0];
5
5
  type Options = Parameters<Create>[1];
@@ -7,7 +7,6 @@ type Helpers = {
7
7
  isSpecificTanstackQueryImport: (node: TSESTree.Identifier, source: string) => boolean;
8
8
  isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
9
9
  };
10
- type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
11
- declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
12
-
13
- export { type EnhancedCreate, detectTanstackQueryImports };
10
+ export type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
11
+ export declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
12
+ export {};
@@ -0,0 +1 @@
1
+ export declare function normalizeIndent(template: TemplateStringsArray): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function uniqueBy(arr, fn) {
4
+ return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i);
5
+ }
6
+ exports.uniqueBy = uniqueBy;
7
+ //# sourceMappingURL=unique-by.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-by.cjs","sources":["../../../src/utils/unique-by.ts"],"sourcesContent":["export function uniqueBy<T>(arr: Array<T>, fn: (x: T) => unknown): Array<T> {\n return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i)\n}\n"],"names":[],"mappings":";;AAAgB,SAAA,SAAY,KAAe,IAAiC;AAC1E,SAAO,IAAI,OAAO,CAAC,GAAG,GAAG,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC1E;;"}
@@ -0,0 +1 @@
1
+ export declare function uniqueBy<T>(arr: Array<T>, fn: (x: T) => unknown): Array<T>;
@@ -0,0 +1,6 @@
1
+ export declare const configs: {
2
+ recommended: {
3
+ plugins: string[];
4
+ rules: Record<string, "error" | "strict" | "warn">;
5
+ };
6
+ };
@@ -1,4 +1,3 @@
1
- // src/configs.ts
2
1
  import { rules } from "./rules.js";
3
2
  function generateRecommendedConfig(allRules) {
4
3
  return Object.entries(allRules).reduce(
@@ -12,7 +11,7 @@ function generateRecommendedConfig(allRules) {
12
11
  {}
13
12
  );
14
13
  }
15
- var configs = {
14
+ const configs = {
16
15
  recommended: {
17
16
  plugins: ["@tanstack/eslint-plugin-query"],
18
17
  rules: generateRecommendedConfig(rules)
@@ -21,4 +20,4 @@ var configs = {
21
20
  export {
22
21
  configs
23
22
  };
24
- //# sourceMappingURL=configs.js.map
23
+ //# sourceMappingURL=configs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configs.js","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(\n (memo, [name, rule]) => {\n const { recommended } = rule.meta.docs || {}\n\n return {\n ...memo,\n ...(recommended ? { [`@tanstack/query/${name}`]: recommended } : {}),\n }\n },\n {} as Record<string, 'strict' | 'error' | 'warn'>,\n )\n}\n\nexport const configs = {\n recommended: {\n plugins: ['@tanstack/eslint-plugin-query'],\n rules: generateRecommendedConfig(rules),\n },\n}\n"],"names":[],"mappings":";AAGA,SAAS,0BACP,UACA;AACO,SAAA,OAAO,QAAQ,QAAQ,EAAE;AAAA,IAC9B,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM;AACtB,YAAM,EAAE,YAAY,IAAI,KAAK,KAAK,QAAQ,CAAA;AAEnC,aAAA;AAAA,QACL,GAAG;AAAA,QACH,GAAI,cAAc,EAAE,CAAC,mBAAmB,IAAI,EAAE,GAAG,YAAY,IAAI,CAAC;AAAA,MAAA;AAAA,IAEtE;AAAA,IACA,CAAC;AAAA,EAAA;AAEL;AAEO,MAAM,UAAU;AAAA,EACrB,aAAa;AAAA,IACX,SAAS,CAAC,+BAA+B;AAAA,IACzC,OAAO,0BAA0B,KAAK;AAAA,EACxC;AACF;"}
@@ -0,0 +1,2 @@
1
+ export { configs } from './configs';
2
+ export { rules } from './rules';
@@ -1,8 +1,7 @@
1
- // src/index.ts
2
1
  import { configs } from "./configs.js";
3
2
  import { rules } from "./rules.js";
4
3
  export {
5
4
  configs,
6
5
  rules
7
6
  };
8
- //# sourceMappingURL=index.js.map
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,3 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export declare const name = "exhaustive-deps";
3
+ export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
@@ -1,13 +1,12 @@
1
- // src/rules/exhaustive-deps.rule.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
2
  import { ASTUtils } from "../utils/ast-utils.js";
4
3
  import { createRule } from "../utils/create-rule.js";
5
4
  import { uniqueBy } from "../utils/unique-by.js";
6
5
  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({
6
+ const QUERY_KEY = "queryKey";
7
+ const QUERY_FN = "queryFn";
8
+ const name = "exhaustive-deps";
9
+ const rule = createRule({
11
10
  name,
12
11
  meta: {
13
12
  type: "problem",
@@ -112,4 +111,4 @@ export {
112
111
  name,
113
112
  rule
114
113
  };
115
- //# sourceMappingURL=exhaustive-deps.rule.js.map
114
+ //# sourceMappingURL=exhaustive-deps.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exhaustive-deps.rule.js","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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;AAAA,YAAA,CACD;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,UAAA,CACV;AAAA,QACH;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
@@ -1,6 +1,5 @@
1
- import { TSESLint } from '@typescript-eslint/utils';
2
-
3
- declare const ExhaustiveDepsUtils: {
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export declare const ExhaustiveDepsUtils: {
4
3
  isRelevantReference(params: {
5
4
  context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>;
6
5
  reference: TSESLint.Scope.Reference;
@@ -8,5 +7,3 @@ declare const ExhaustiveDepsUtils: {
8
7
  }): boolean;
9
8
  isQueryClientReference(reference: TSESLint.Scope.Reference): boolean;
10
9
  };
11
-
12
- export { ExhaustiveDepsUtils };
@@ -1,7 +1,6 @@
1
- // src/rules/exhaustive-deps.utils.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
2
  import { ASTUtils } from "../utils/ast-utils.js";
4
- var ExhaustiveDepsUtils = {
3
+ const ExhaustiveDepsUtils = {
5
4
  isRelevantReference(params) {
6
5
  var _a;
7
6
  const { reference, scopeManager, context } = params;
@@ -24,4 +23,4 @@ var ExhaustiveDepsUtils = {
24
23
  export {
25
24
  ExhaustiveDepsUtils
26
25
  };
27
- //# sourceMappingURL=exhaustive-deps.utils.js.map
26
+ //# sourceMappingURL=exhaustive-deps.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exhaustive-deps.utils.js","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, ReadonlyArray<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"],"names":[],"mappings":";;AAIO,MAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;;AACD,UAAM,EAAE,WAAW,cAAc,QAAA,IAAY;AACvC,UAAA,YAAY,SAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAAC,SAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAAA,CACf,GACD;AACO,aAAA;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;;AAC1D,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;"}
@@ -0,0 +1,2 @@
1
+ export declare const name = "no-rest-destructuring";
2
+ export declare const rule: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
@@ -1,11 +1,10 @@
1
- // src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
2
  import { createRule } from "../../utils/create-rule.js";
4
3
  import { ASTUtils } from "../../utils/ast-utils.js";
5
4
  import { NoRestDestructuringUtils } from "./no-rest-destructuring.utils.js";
6
- var name = "no-rest-destructuring";
7
- var queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
8
- var rule = createRule({
5
+ const name = "no-rest-destructuring";
6
+ const queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
7
+ const rule = createRule({
9
8
  name,
10
9
  meta: {
11
10
  type: "problem",
@@ -58,4 +57,4 @@ export {
58
57
  name,
59
58
  rule
60
59
  };
61
- //# sourceMappingURL=no-rest-destructuring.rule.js.map
60
+ //# sourceMappingURL=no-rest-destructuring.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-rest-destructuring.rule.js","sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { createRule } from '../../utils/create-rule'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { NoRestDestructuringUtils } from './no-rest-destructuring.utils'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Disallows rest destructuring in queries',\n recommended: 'warn',\n },\n messages: {\n objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`,\n },\n schema: [],\n },\n defaultOptions: [],\n\n create(context, _, helpers) {\n return {\n CallExpression(node) {\n if (\n !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||\n !helpers.isTanstackQueryImport(node.callee) ||\n node.parent?.type !== AST_NODE_TYPES.VariableDeclarator\n ) {\n return\n }\n\n const returnValue = node.parent.id\n if (node.callee.name !== 'useQueries') {\n if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {\n context.report({\n node: node.parent,\n messageId: 'objectRestDestructure',\n })\n }\n return\n }\n\n if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {\n return\n }\n returnValue.elements.forEach((queryResult) => {\n if (queryResult === null) {\n return\n }\n if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {\n context.report({\n node: queryResult,\n messageId: 'objectRestDestructure',\n })\n }\n })\n },\n }\n },\n})\n"],"names":[],"mappings":";;;;AAKO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,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,uBAAuB;AAAA,IACzB;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS,GAAG,SAAS;AACnB,WAAA;AAAA,MACL,eAAe,MAAM;;AACnB,YACE,CAAC,SAAS,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAAS,eAAe,oBACrC;AACA;AAAA,QACF;AAEM,cAAA,cAAc,KAAK,OAAO;AAC5B,YAAA,KAAK,OAAO,SAAS,cAAc;AACjC,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AACA;AAAA,QACF;AAEI,YAAA,YAAY,SAAS,eAAe,cAAc;AACpD;AAAA,QACF;AACY,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACI,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AAAA,QAAA,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
@@ -0,0 +1,4 @@
1
+ import type { TSESTree } from '@typescript-eslint/utils';
2
+ export declare const NoRestDestructuringUtils: {
3
+ isObjectRestDestructuring(node: TSESTree.Node): boolean;
4
+ };
@@ -1,6 +1,5 @@
1
- // src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
- var NoRestDestructuringUtils = {
2
+ const NoRestDestructuringUtils = {
4
3
  isObjectRestDestructuring(node) {
5
4
  if (node.type !== AST_NODE_TYPES.ObjectPattern) {
6
5
  return false;
@@ -11,4 +10,4 @@ var NoRestDestructuringUtils = {
11
10
  export {
12
11
  NoRestDestructuringUtils
13
12
  };
14
- //# sourceMappingURL=no-rest-destructuring.utils.js.map
13
+ //# sourceMappingURL=no-rest-destructuring.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-rest-destructuring.utils.js","sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"names":[],"mappings":";AAGO,MAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AAClD,QAAA,KAAK,SAAS,eAAe,eAAe;AACvC,aAAA;AAAA,IACT;AACO,WAAA,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,eAAe,WAAW;AAAA,EAC1E;AACF;"}
@@ -0,0 +1,3 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export declare const name = "stable-query-client";
3
+ export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
@@ -1,9 +1,8 @@
1
- // src/rules/stable-query-client/stable-query-client.rule.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
2
  import { ASTUtils } from "../../utils/ast-utils.js";
4
3
  import { createRule } from "../../utils/create-rule.js";
5
- var name = "stable-query-client";
6
- var rule = createRule({
4
+ const name = "stable-query-client";
5
+ const rule = createRule({
7
6
  name,
8
7
  meta: {
9
8
  type: "problem",
@@ -64,4 +63,4 @@ export {
64
63
  name,
65
64
  rule
66
65
  };
67
- //# sourceMappingURL=stable-query-client.rule.js.map
66
+ //# sourceMappingURL=stable-query-client.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-query-client.rule.js","sources":["../../../../src/rules/stable-query-client/stable-query-client.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { createRule } from '../../utils/create-rule'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const name = 'stable-query-client'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Makes sure that QueryClient is stable',\n recommended: 'error',\n },\n messages: {\n unstable: [\n 'QueryClient is not stable. It should be either extracted from the component or wrapped in React.useState.',\n 'See https://tkdodo.eu/blog/react-query-fa-qs#2-the-queryclient-is-not-stable',\n ].join('\\n'),\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context, _, helpers) {\n return {\n NewExpression(node) {\n if (\n node.callee.type !== AST_NODE_TYPES.Identifier ||\n node.callee.name !== 'QueryClient' ||\n node.parent?.type !== AST_NODE_TYPES.VariableDeclarator ||\n !helpers.isSpecificTanstackQueryImport(\n node.callee,\n '@tanstack/react-query',\n )\n ) {\n return\n }\n\n const fnAncestor = ASTUtils.getFunctionAncestor(context)\n const isReactServerComponent = fnAncestor?.async === true\n\n if (\n !ASTUtils.isValidReactComponentOrHookName(fnAncestor?.id) ||\n isReactServerComponent\n ) {\n return\n }\n\n context.report({\n node: node.parent,\n messageId: 'unstable',\n fix: (() => {\n const { parent } = node\n\n if (parent.id.type !== AST_NODE_TYPES.Identifier) {\n return\n }\n\n const nodeText = context.getSourceCode().getText(node)\n const variableName = parent.id.name\n\n return (fixer: TSESLint.RuleFixer) => {\n return fixer.replaceTextRange(\n [parent.range[0], parent.range[1]],\n `[${variableName}] = React.useState(() => ${nodeText})`,\n )\n }\n })(),\n })\n },\n }\n },\n})\n"],"names":[],"mappings":";;;AAKO,MAAM,OAAO;AAEb,MAAM,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,UAAU;AAAA,QACR;AAAA,QACA;AAAA,MAAA,EACA,KAAK,IAAI;AAAA,MACX,OAAO;AAAA,IACT;AAAA,IACA,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS,GAAG,SAAS;AACnB,WAAA;AAAA,MACL,cAAc,MAAM;;AAClB,YACE,KAAK,OAAO,SAAS,eAAe,cACpC,KAAK,OAAO,SAAS,mBACrB,UAAK,WAAL,mBAAa,UAAS,eAAe,sBACrC,CAAC,QAAQ;AAAA,UACP,KAAK;AAAA,UACL;AAAA,QAAA,GAEF;AACA;AAAA,QACF;AAEM,cAAA,aAAa,SAAS,oBAAoB,OAAO;AACjD,cAAA,0BAAyB,yCAAY,WAAU;AAErD,YACE,CAAC,SAAS,gCAAgC,yCAAY,EAAE,KACxD,wBACA;AACA;AAAA,QACF;AAEA,gBAAQ,OAAO;AAAA,UACb,MAAM,KAAK;AAAA,UACX,WAAW;AAAA,UACX,MAAM,MAAM;AACJ,kBAAA,EAAE,OAAW,IAAA;AAEnB,gBAAI,OAAO,GAAG,SAAS,eAAe,YAAY;AAChD;AAAA,YACF;AAEA,kBAAM,WAAW,QAAQ,cAAc,EAAE,QAAQ,IAAI;AAC/C,kBAAA,eAAe,OAAO,GAAG;AAE/B,mBAAO,CAAC,UAA8B;AACpC,qBAAO,MAAM;AAAA,gBACX,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC;AAAA,gBACjC,IAAI,YAAY,4BAA4B,QAAQ;AAAA,cAAA;AAAA,YACtD;AAAA,UACF,GACC;AAAA,QAAA,CACJ;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
@@ -0,0 +1,5 @@
1
+ export declare const rules: {
2
+ "exhaustive-deps": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
3
+ "stable-query-client": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
4
+ "no-rest-destructuring": import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
5
+ };
@@ -0,0 +1,12 @@
1
+ import { name, rule } from "./rules/exhaustive-deps.rule.js";
2
+ import { name as name$1, rule as rule$1 } from "./rules/stable-query-client/stable-query-client.rule.js";
3
+ import { name as name$2, rule as rule$2 } from "./rules/no-rest-desctructuring/no-rest-destructuring.rule.js";
4
+ const rules = {
5
+ [name]: rule,
6
+ [name$1]: rule$1,
7
+ [name$2]: rule$2
8
+ };
9
+ export {
10
+ rules
11
+ };
12
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sources":["../../src/rules.ts"],"sourcesContent":["import * as exhaustiveDeps from './rules/exhaustive-deps.rule'\nimport * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'\nimport * as noRestDestructuring from './rules/no-rest-desctructuring/no-rest-destructuring.rule'\n\nexport const rules = {\n [exhaustiveDeps.name]: exhaustiveDeps.rule,\n [stableQueryClient.name]: stableQueryClient.rule,\n [noRestDestructuring.name]: noRestDestructuring.rule,\n}\n"],"names":["exhaustiveDeps.name","exhaustiveDeps.rule","stableQueryClient.name","stableQueryClient.rule","noRestDestructuring.name","noRestDestructuring.rule"],"mappings":";;;AAIO,MAAM,QAAQ;AAAA,EACnB,CAACA,IAAmB,GAAGC;AAAAA,EACvB,CAACC,MAAsB,GAAGC;AAAAA,EAC1B,CAACC,MAAwB,GAAGC;AAC9B;"}
@@ -1,7 +1,7 @@
1
- import { AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils';
2
- import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
3
-
4
- declare const ASTUtils: {
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
3
+ import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
4
+ export declare const ASTUtils: {
5
5
  isNodeOfOneOf<T extends AST_NODE_TYPES>(node: TSESTree.Node, types: readonly T[]): node is TSESTree.Node & {
6
6
  type: T;
7
7
  };
@@ -37,5 +37,3 @@ declare const ASTUtils: {
37
37
  getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.VariableDeclarator | undefined;
38
38
  getNestedReturnStatements(node: TSESTree.Node): Array<TSESTree.ReturnStatement>;
39
39
  };
40
-
41
- export { ASTUtils };
@@ -1,7 +1,6 @@
1
- // src/utils/ast-utils.ts
2
1
  import { AST_NODE_TYPES } from "@typescript-eslint/utils";
3
2
  import { uniqueBy } from "./unique-by.js";
4
- var ASTUtils = {
3
+ const ASTUtils = {
5
4
  isNodeOfOneOf(node, types) {
6
5
  return types.includes(node.type);
7
6
  },
@@ -232,4 +231,4 @@ var ASTUtils = {
232
231
  export {
233
232
  ASTUtils
234
233
  };
235
- //# sourceMappingURL=ast-utils.js.map
234
+ //# sourceMappingURL=ast-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-utils.js","sources":["../../../src/utils/ast-utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport { uniqueBy } from './unique-by'\nimport type { TSESLint, TSESTree } from '@typescript-eslint/utils'\nimport type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'\n\nexport const ASTUtils = {\n isNodeOfOneOf<T extends AST_NODE_TYPES>(\n node: TSESTree.Node,\n types: ReadonlyArray<T>,\n ): node is TSESTree.Node & { type: T } {\n return types.includes(node.type as T)\n },\n isIdentifier(node: TSESTree.Node): node is TSESTree.Identifier {\n return node.type === AST_NODE_TYPES.Identifier\n },\n isIdentifierWithName(\n node: TSESTree.Node,\n name: string,\n ): node is TSESTree.Identifier {\n return ASTUtils.isIdentifier(node) && node.name === name\n },\n isIdentifierWithOneOfNames<T extends Array<string>>(\n node: TSESTree.Node,\n name: T,\n ): node is TSESTree.Identifier & { name: T[number] } {\n return ASTUtils.isIdentifier(node) && name.includes(node.name)\n },\n isProperty(node: TSESTree.Node): node is TSESTree.Property {\n return node.type === AST_NODE_TYPES.Property\n },\n isObjectExpression(node: TSESTree.Node): node is TSESTree.ObjectExpression {\n return node.type === AST_NODE_TYPES.ObjectExpression\n },\n isPropertyWithIdentifierKey(\n node: TSESTree.Node,\n key: string,\n ): node is TSESTree.Property {\n return (\n ASTUtils.isProperty(node) && ASTUtils.isIdentifierWithName(node.key, key)\n )\n },\n findPropertyWithIdentifierKey(\n properties: Array<TSESTree.ObjectLiteralElement>,\n key: string,\n ): TSESTree.Property | undefined {\n return properties.find((x) =>\n ASTUtils.isPropertyWithIdentifierKey(x, key),\n ) as TSESTree.Property | undefined\n },\n getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier> {\n const identifiers: Array<TSESTree.Identifier> = []\n\n if (ASTUtils.isIdentifier(node)) {\n identifiers.push(node)\n }\n\n if ('arguments' in node) {\n node.arguments.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('elements' in node) {\n node.elements.forEach((x) => {\n if (x !== null) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n }\n })\n }\n\n if ('properties' in node) {\n node.properties.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if ('expressions' in node) {\n node.expressions.forEach((x) => {\n identifiers.push(...ASTUtils.getNestedIdentifiers(x))\n })\n }\n\n if (node.type === AST_NODE_TYPES.Property) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.value))\n }\n\n if (node.type === AST_NODE_TYPES.SpreadElement) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.MemberExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.object))\n }\n\n if (node.type === AST_NODE_TYPES.UnaryExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.argument))\n }\n\n if (node.type === AST_NODE_TYPES.ChainExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n if (node.type === AST_NODE_TYPES.TSNonNullExpression) {\n identifiers.push(...ASTUtils.getNestedIdentifiers(node.expression))\n }\n\n return identifiers\n },\n isAncestorIsCallee(identifier: TSESTree.Node) {\n let previousNode = identifier\n let currentNode = identifier.parent\n\n while (currentNode !== undefined) {\n if (\n currentNode.type === AST_NODE_TYPES.CallExpression &&\n currentNode.callee === previousNode\n ) {\n return true\n }\n\n if (currentNode.type !== AST_NODE_TYPES.MemberExpression) {\n return false\n }\n\n previousNode = currentNode\n currentNode = currentNode.parent\n }\n\n return false\n },\n traverseUpOnly(\n identifier: TSESTree.Node,\n allowedNodeTypes: Array<AST_NODE_TYPES>,\n ): TSESTree.Node {\n const parent = identifier.parent\n\n if (parent !== undefined && allowedNodeTypes.includes(parent.type)) {\n return ASTUtils.traverseUpOnly(parent, allowedNodeTypes)\n }\n\n return identifier\n },\n isDeclaredInNode(params: {\n functionNode: TSESTree.Node\n reference: TSESLint.Scope.Reference\n scopeManager: TSESLint.Scope.ScopeManager\n }) {\n const { functionNode, reference, scopeManager } = params\n const scope = scopeManager.acquire(functionNode)\n\n if (scope === null) {\n return false\n }\n\n return scope.set.has(reference.identifier.name)\n },\n getExternalRefs(params: {\n scopeManager: TSESLint.Scope.ScopeManager\n sourceCode: Readonly<TSESLint.SourceCode>\n node: TSESTree.Node\n }): Array<TSESLint.Scope.Reference> {\n const { scopeManager, sourceCode, node } = params\n const scope = scopeManager.acquire(node)\n\n if (scope === null) {\n return []\n }\n\n const references = scope.references\n .filter((x) => x.isRead() && !scope.set.has(x.identifier.name))\n .map((x) => {\n const referenceNode = ASTUtils.traverseUpOnly(x.identifier, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.Identifier,\n ])\n\n return {\n variable: x,\n node: referenceNode,\n text: sourceCode.getText(referenceNode),\n }\n })\n\n const localRefIds = new Set(\n [...scope.set.values()].map((x) => sourceCode.getText(x.identifiers[0])),\n )\n\n const externalRefs = references.filter(\n (x) => x.variable.resolved === null || !localRefIds.has(x.text),\n )\n\n return uniqueBy(externalRefs, (x) => x.text).map((x) => x.variable)\n },\n mapKeyNodeToText(\n node: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n ) {\n return sourceCode.getText(\n ASTUtils.traverseUpOnly(node, [\n AST_NODE_TYPES.MemberExpression,\n AST_NODE_TYPES.Identifier,\n ]),\n )\n },\n isValidReactComponentOrHookName(\n identifier: TSESTree.Identifier | null | undefined,\n ) {\n return (\n identifier !== null &&\n identifier !== undefined &&\n /^(use|[A-Z])/.test(identifier.name)\n )\n },\n getFunctionAncestor(\n context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>,\n ) {\n for (const ancestor of context.getAncestors()) {\n if (ancestor.type === AST_NODE_TYPES.FunctionDeclaration) {\n return ancestor\n }\n\n if (\n ancestor.parent?.type === AST_NODE_TYPES.VariableDeclarator &&\n ancestor.parent.id.type === AST_NODE_TYPES.Identifier &&\n ASTUtils.isNodeOfOneOf(ancestor, [\n AST_NODE_TYPES.FunctionDeclaration,\n AST_NODE_TYPES.FunctionExpression,\n AST_NODE_TYPES.ArrowFunctionExpression,\n ])\n ) {\n return ancestor\n }\n }\n\n return undefined\n },\n getReferencedExpressionByIdentifier(params: {\n node: TSESTree.Node\n context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>\n }) {\n const { node, context } = params\n\n const resolvedNode = context\n .getScope()\n .references.find((ref) => ref.identifier === node)?.resolved?.defs[0]\n ?.node\n\n if (resolvedNode?.type !== AST_NODE_TYPES.VariableDeclarator) {\n return null\n }\n\n return resolvedNode.init\n },\n getClosestVariableDeclarator(node: TSESTree.Node) {\n let currentNode: TSESTree.Node | undefined = node\n\n while (\n currentNode !== undefined &&\n currentNode.type !== AST_NODE_TYPES.Program\n ) {\n if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {\n return currentNode\n }\n\n currentNode = currentNode.parent\n }\n\n return undefined\n },\n getNestedReturnStatements(\n node: TSESTree.Node,\n ): Array<TSESTree.ReturnStatement> {\n const returnStatements: Array<TSESTree.ReturnStatement> = []\n\n if (node.type === AST_NODE_TYPES.ReturnStatement) {\n returnStatements.push(node)\n }\n\n if ('body' in node && node.body !== undefined && node.body !== null) {\n Array.isArray(node.body)\n ? node.body.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.body),\n )\n }\n\n if ('consequent' in node) {\n Array.isArray(node.consequent)\n ? node.consequent.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.consequent),\n )\n }\n\n if ('alternate' in node && node.alternate !== null) {\n Array.isArray(node.alternate)\n ? node.alternate.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n : returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.alternate),\n )\n }\n\n if ('cases' in node) {\n node.cases.forEach((x) => {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(x))\n })\n }\n\n if ('block' in node) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.block))\n }\n\n if ('handler' in node && node.handler !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.handler))\n }\n\n if ('finalizer' in node && node.finalizer !== null) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.finalizer),\n )\n }\n\n if (\n 'expression' in node &&\n node.expression !== true &&\n node.expression !== false\n ) {\n returnStatements.push(\n ...ASTUtils.getNestedReturnStatements(node.expression),\n )\n }\n\n if ('test' in node && node.test !== null) {\n returnStatements.push(...ASTUtils.getNestedReturnStatements(node.test))\n }\n\n return returnStatements\n },\n}\n"],"names":[],"mappings":";;AAKO,MAAM,WAAW;AAAA,EACtB,cACE,MACA,OACqC;AAC9B,WAAA,MAAM,SAAS,KAAK,IAAS;AAAA,EACtC;AAAA,EACA,aAAa,MAAkD;AACtD,WAAA,KAAK,SAAS,eAAe;AAAA,EACtC;AAAA,EACA,qBACE,MACA,MAC6B;AAC7B,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS;AAAA,EACtD;AAAA,EACA,2BACE,MACA,MACmD;AACnD,WAAO,SAAS,aAAa,IAAI,KAAK,KAAK,SAAS,KAAK,IAAI;AAAA,EAC/D;AAAA,EACA,WAAW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@typescript-eslint/utils';
2
+ import type { EnhancedCreate } from './detect-react-query-imports';
3
+ type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
4
+ create: EnhancedCreate;
5
+ };
6
+ export declare function createRule({ create, ...rest }: EslintRule): import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>;
7
+ export {};
@@ -1,7 +1,6 @@
1
- // src/utils/create-rule.ts
2
1
  import { ESLintUtils } from "@typescript-eslint/utils";
3
2
  import { detectTanstackQueryImports } from "./detect-react-query-imports.js";
4
- var getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
3
+ const getDocsUrl = (ruleName) => `https://tanstack.com/query/v4/docs/eslint/${ruleName}`;
5
4
  function createRule({ create, ...rest }) {
6
5
  return ESLintUtils.RuleCreator(getDocsUrl)({
7
6
  ...rest,
@@ -11,4 +10,4 @@ function createRule({ create, ...rest }) {
11
10
  export {
12
11
  createRule
13
12
  };
14
- //# sourceMappingURL=create-rule.js.map
13
+ //# sourceMappingURL=create-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-rule.js","sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/v4/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"names":[],"mappings":";;AAIA,MAAM,aAAa,CAAC,aAClB,6CAA6C,QAAQ;AAShD,SAAS,WAAW,EAAE,QAAQ,GAAG,QAAoB;AACnD,SAAA,YAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,QAAQ,2BAA2B,MAAM;AAAA,EAAA,CAC1C;AACH;"}
@@ -1,5 +1,5 @@
1
- import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
2
-
1
+ import { TSESTree } from '@typescript-eslint/utils';
2
+ import type { ESLintUtils } from '@typescript-eslint/utils';
3
3
  type Create = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]['create'];
4
4
  type Context = Parameters<Create>[0];
5
5
  type Options = Parameters<Create>[1];
@@ -7,7 +7,6 @@ type Helpers = {
7
7
  isSpecificTanstackQueryImport: (node: TSESTree.Identifier, source: string) => boolean;
8
8
  isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
9
9
  };
10
- type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
11
- declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
12
-
13
- export { type EnhancedCreate, detectTanstackQueryImports };
10
+ export type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
11
+ export declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
12
+ export {};
@@ -1,4 +1,3 @@
1
- // src/utils/detect-react-query-imports.ts
2
1
  import { TSESTree } from "@typescript-eslint/utils";
3
2
  function detectTanstackQueryImports(create) {
4
3
  return (context, optionsWithDefault) => {
@@ -52,4 +51,4 @@ function detectTanstackQueryImports(create) {
52
51
  export {
53
52
  detectTanstackQueryImports
54
53
  };
55
- //# sourceMappingURL=detect-react-query-imports.js.map
54
+ //# sourceMappingURL=detect-react-query-imports.js.map