@tanstack/eslint-plugin-query 5.18.0 → 5.20.0

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 (56) hide show
  1. package/dist/cjs/configs.cjs +1 -0
  2. package/dist/cjs/configs.cjs.map +1 -1
  3. package/dist/cjs/configs.d.cts +2 -1
  4. package/dist/cjs/rules/exhaustive-deps.rule.cjs +3 -3
  5. package/dist/cjs/rules/exhaustive-deps.rule.cjs.map +1 -1
  6. package/dist/cjs/rules/exhaustive-deps.rule.d.cts +2 -2
  7. package/dist/cjs/rules/exhaustive-deps.utils.cjs +1 -2
  8. package/dist/cjs/rules/exhaustive-deps.utils.cjs.map +1 -1
  9. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs +3 -4
  10. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs.map +1 -1
  11. package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.cts +2 -1
  12. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs +3 -4
  13. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs.map +1 -1
  14. package/dist/cjs/rules/stable-query-client/stable-query-client.rule.d.cts +2 -2
  15. package/dist/cjs/rules.cjs.map +1 -1
  16. package/dist/cjs/rules.d.cts +2 -5
  17. package/dist/cjs/utils/ast-utils.cjs +1 -1
  18. package/dist/cjs/utils/ast-utils.cjs.map +1 -1
  19. package/dist/cjs/utils/ast-utils.d.cts +3 -4
  20. package/dist/cjs/utils/create-rule.d.cts +1 -1
  21. package/dist/cjs/utils/detect-react-query-imports.cjs +1 -2
  22. package/dist/cjs/utils/detect-react-query-imports.cjs.map +1 -1
  23. package/dist/esm/configs.d.ts +2 -1
  24. package/dist/esm/configs.js +1 -0
  25. package/dist/esm/configs.js.map +1 -1
  26. package/dist/esm/rules/exhaustive-deps.rule.d.ts +2 -2
  27. package/dist/esm/rules/exhaustive-deps.rule.js +3 -3
  28. package/dist/esm/rules/exhaustive-deps.rule.js.map +1 -1
  29. package/dist/esm/rules/exhaustive-deps.utils.js +1 -2
  30. package/dist/esm/rules/exhaustive-deps.utils.js.map +1 -1
  31. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.ts +2 -1
  32. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.js +3 -4
  33. package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.js.map +1 -1
  34. package/dist/esm/rules/stable-query-client/stable-query-client.rule.d.ts +2 -2
  35. package/dist/esm/rules/stable-query-client/stable-query-client.rule.js +3 -4
  36. package/dist/esm/rules/stable-query-client/stable-query-client.rule.js.map +1 -1
  37. package/dist/esm/rules.d.ts +2 -5
  38. package/dist/esm/rules.js.map +1 -1
  39. package/dist/esm/utils/ast-utils.d.ts +3 -4
  40. package/dist/esm/utils/ast-utils.js +1 -1
  41. package/dist/esm/utils/ast-utils.js.map +1 -1
  42. package/dist/esm/utils/create-rule.d.ts +1 -1
  43. package/dist/esm/utils/detect-react-query-imports.js +1 -2
  44. package/dist/esm/utils/detect-react-query-imports.js.map +1 -1
  45. package/package.json +3 -2
  46. package/src/__tests__/exhaustive-deps.test.ts +2 -2
  47. package/src/configs.ts +1 -0
  48. package/src/rules/exhaustive-deps.rule.ts +9 -6
  49. package/src/rules/exhaustive-deps.utils.ts +1 -1
  50. package/src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts +10 -5
  51. package/src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts +2 -2
  52. package/src/rules/stable-query-client/stable-query-client.rule.ts +10 -5
  53. package/src/rules/stable-query-client/stable-query-client.test.ts +2 -2
  54. package/src/rules.ts +5 -1
  55. package/src/utils/ast-utils.ts +3 -7
  56. package/src/utils/detect-react-query-imports.ts +1 -1
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const rules = require("./rules.cjs");
4
4
  function generateRecommendedConfig(allRules) {
5
5
  return Object.entries(allRules).reduce(
6
+ // @ts-expect-error
6
7
  (memo, [name, rule]) => {
7
8
  const { recommended } = rule.meta.docs || {};
8
9
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"configs.cjs","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":["rules"],"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,0BAA0BA,WAAK;AAAA,EACxC;AACF;;"}
1
+ {"version":3,"file":"configs.cjs","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 // @ts-expect-error\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":["rules"],"mappings":";;;AAGA,SAAS,0BACP,UACA;AACO,SAAA,OAAO,QAAQ,QAAQ,EAAE;AAAA;AAAA,IAE9B,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,0BAA0BA,WAAK;AAAA,EACxC;AACF;;"}
@@ -1,6 +1,7 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
1
2
  export declare const configs: {
2
3
  recommended: {
3
4
  plugins: string[];
4
- rules: Record<string, "error" | "strict" | "warn">;
5
+ rules: [string, TSESLint.RuleModule<any, any, TSESLint.RuleListener>];
5
6
  };
6
7
  };
@@ -25,10 +25,10 @@ const rule = createRule.createRule({
25
25
  schema: []
26
26
  },
27
27
  defaultOptions: [],
28
- create(context) {
28
+ create: (context) => {
29
29
  return {
30
- Property(node) {
31
- if (node.parent === void 0 || !astUtils.ASTUtils.isObjectExpression(node.parent) || !astUtils.ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
30
+ Property: (node) => {
31
+ if (!astUtils.ASTUtils.isObjectExpression(node.parent) || !astUtils.ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
32
32
  return;
33
33
  }
34
34
  const scopeManager = context.getSourceCode().scopeManager;
@@ -1 +1 @@
1
- {"version":3,"file":"exhaustive-deps.rule.cjs","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"],"names":["createRule","ASTUtils","AST_NODE_TYPES","ExhaustiveDepsUtils","uniqueBy"],"mappings":";;;;;;;AAOA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AAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACF,uBAAA,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;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
+ {"version":3,"file":"exhaustive-deps.rule.cjs","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 { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error' as any,\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 !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"],"names":["createRule","ASTUtils","AST_NODE_TYPES","ExhaustiveDepsUtils","uniqueBy"],"mappings":";;;;;;;AAOA,MAAM,YAAY;AAClB,MAAM,WAAW;AAEV,MAAM,OAAO;AAEb,MAAM,OAITA,WAAAA,WAAW;AAAA,EACb;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,QAAQ,CAAC,YAAY;AACZ,WAAA;AAAA,MACL,UAAU,CAAC,SAAS;AAClB,YACE,CAACC,SAAA,SAAS,mBAAmB,KAAK,MAAM,KACxC,CAACA,SAAA,SAAS,qBAAqB,KAAK,KAAK,SAAS,GAClD;AACA;AAAA,QACF;AAEM,cAAA,eAAe,QAAQ,cAAA,EAAgB;AAC7C,cAAM,WAAWA,SAAAA,SAAS;AAAA,UACxB,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAEF,cAAM,UAAUA,SAAAA,SAAS;AAAA,UACvB,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAIA,YAAA,iBAAiB,QACjB,aAAa,UACb,YAAY,UACZ,QAAQ,MAAM,SAASC,MAAAA,eAAe,yBACt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AoBG,SAAAA,SAAS,aAAa,CAAC,MAAM,EAAE,IAAI;AAEzD,YAAA,kBAAkB,SAAS,GAAG;AAChC,gBAAM,gBAAgB,kBACnB,IAAI,CAAC,QAAQH,SAAAA,SAAS,iBAAiB,IAAI,YAAY,UAAU,CAAC,EAClE,KAAK,IAAI;AAEN,gBAAA,sBAAsB,WACzB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KAAK,aAAa,GAAG;AAEvC,gBAAM,cAAsD,CAAA;AAExD,cAAA,aAAa,SAASC,MAAA,eAAe,iBAAiB;AACxD,wBAAY,KAAK;AAAA,cACf,WAAW;AAAA,cACX,MAAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACF,uBAAA,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;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,3 +1,3 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
2
  export declare const name = "exhaustive-deps";
3
- export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -4,7 +4,6 @@ const utils = require("@typescript-eslint/utils");
4
4
  const astUtils = require("../utils/ast-utils.cjs");
5
5
  const ExhaustiveDepsUtils = {
6
6
  isRelevantReference(params) {
7
- var _a;
8
7
  const { reference, scopeManager, context } = params;
9
8
  const component = astUtils.ASTUtils.getFunctionAncestor(context);
10
9
  if (component !== void 0 && !astUtils.ASTUtils.isDeclaredInNode({
@@ -14,7 +13,7 @@ const ExhaustiveDepsUtils = {
14
13
  })) {
15
14
  return false;
16
15
  }
17
- return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== utils.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
16
+ return reference.identifier.name !== "undefined" && reference.identifier.parent.type !== utils.AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
18
17
  },
19
18
  isQueryClientReference(reference) {
20
19
  var _a, _b, _c;
@@ -1 +1 @@
1
- {"version":3,"file":"exhaustive-deps.utils.cjs","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":["ASTUtils","AST_NODE_TYPES"],"mappings":";;;;AAIO,MAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;;AACD,UAAM,EAAE,WAAW,cAAc,QAAA,IAAY;AACvC,UAAA,YAAYA,SAAAA,SAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAACA,SAAAA,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,UAASC,MAAAA,eAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;;AAC1D,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAASA,MAAAA,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAASA,MAAe,eAAA,kBACzC,WAAW,KAAK,OAAO,SAASA,MAAAA,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;;"}
1
+ {"version":3,"file":"exhaustive-deps.utils.cjs","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":["ASTUtils","AST_NODE_TYPES"],"mappings":";;;;AAIO,MAAM,sBAAsB;AAAA,EACjC,oBAAoB,QAIjB;AACD,UAAM,EAAE,WAAW,cAAc,QAAA,IAAY;AACvC,UAAA,YAAYA,SAAAA,SAAS,oBAAoB,OAAO;AAEtD,QACE,cAAc,UACd,CAACA,SAAAA,SAAS,iBAAiB;AAAA,MACzB;AAAA,MACA;AAAA,MACA,cAAc;AAAA,IAAA,CACf,GACD;AACO,aAAA;AAAA,IACT;AAEA,WACE,UAAU,WAAW,SAAS,eAC9B,UAAU,WAAW,OAAO,SAASC,MAAAA,eAAe,iBACpD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;;AAC1D,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAASA,MAAAA,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAASA,MAAe,eAAA,kBACzC,WAAW,KAAK,OAAO,SAASA,MAAAA,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;;"}
@@ -20,11 +20,10 @@ const rule = createRule.createRule({
20
20
  schema: []
21
21
  },
22
22
  defaultOptions: [],
23
- create(context, _, helpers) {
23
+ create: (context, _, helpers) => {
24
24
  return {
25
- CallExpression(node) {
26
- var _a;
27
- if (!astUtils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || ((_a = node.parent) == null ? void 0 : _a.type) !== utils.AST_NODE_TYPES.VariableDeclarator) {
25
+ CallExpression: (node) => {
26
+ if (!astUtils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator) {
28
27
  return;
29
28
  }
30
29
  const returnValue = node.parent.id;
@@ -1 +1 @@
1
- {"version":3,"file":"no-rest-destructuring.rule.cjs","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":["createRule","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;AAKO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,OAAOA,WAAAA,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,CAACC,SAAS,SAAA,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAASC,qBAAe,oBACrC;AACA;AAAA,QACF;AAEM,cAAA,cAAc,KAAK,OAAO;AAC5B,YAAA,KAAK,OAAO,SAAS,cAAc;AACjC,cAAAC,0BAAA,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,SAASD,MAAA,eAAe,cAAc;AACpD;AAAA,QACF;AACY,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACI,cAAAC,0BAAA,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;;;"}
1
+ {"version":3,"file":"no-rest-destructuring.rule.cjs","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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Disallows rest destructuring in queries',\n recommended: 'warn' as any,\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":["createRule","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;AAMO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,OAITA,WAAAA,WAAW;AAAA,EACb;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,QAAQ,CAAC,SAAS,GAAG,YAAY;AACxB,WAAA;AAAA,MACL,gBAAgB,CAAC,SAAS;AACxB,YACE,CAACC,SAAS,SAAA,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,KAC1C,KAAK,OAAO,SAASC,qBAAe,oBACpC;AACA;AAAA,QACF;AAEM,cAAA,cAAc,KAAK,OAAO;AAC5B,YAAA,KAAK,OAAO,SAAS,cAAc;AACjC,cAAAC,0BAAA,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,SAASD,MAAA,eAAe,cAAc;AACpD;AAAA,QACF;AACY,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACI,cAAAC,0BAAA,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;;;"}
@@ -1,2 +1,3 @@
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
1
2
  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>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -24,11 +24,10 @@ const rule = createRule.createRule({
24
24
  schema: []
25
25
  },
26
26
  defaultOptions: [],
27
- create(context, _, helpers) {
27
+ create: (context, _, helpers) => {
28
28
  return {
29
- NewExpression(node) {
30
- var _a;
31
- if (node.callee.type !== utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || ((_a = node.parent) == null ? void 0 : _a.type) !== utils.AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
29
+ NewExpression: (node) => {
30
+ if (node.callee.type !== utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
32
31
  node.callee,
33
32
  "@tanstack/react-query"
34
33
  )) {
@@ -1 +1 @@
1
- {"version":3,"file":"stable-query-client.rule.cjs","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":["createRule","AST_NODE_TYPES","ASTUtils"],"mappings":";;;;;AAKO,MAAM,OAAO;AAEb,MAAM,OAAOA,WAAAA,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,SAASC,MAAA,eAAe,cACpC,KAAK,OAAO,SAAS,mBACrB,UAAK,WAAL,mBAAa,UAASA,MAAe,eAAA,sBACrC,CAAC,QAAQ;AAAA,UACP,KAAK;AAAA,UACL;AAAA,QAAA,GAEF;AACA;AAAA,QACF;AAEM,cAAA,aAAaC,SAAAA,SAAS,oBAAoB,OAAO;AACjD,cAAA,0BAAyB,yCAAY,WAAU;AAErD,YACE,CAACA,SAAS,SAAA,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,SAASD,MAAAA,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;;;"}
1
+ {"version":3,"file":"stable-query-client.rule.cjs","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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const name = 'stable-query-client'\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Makes sure that QueryClient is stable',\n recommended: 'error' as any,\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":["createRule","AST_NODE_TYPES","ASTUtils"],"mappings":";;;;;AAMO,MAAM,OAAO;AAEb,MAAM,OAITA,WAAAA,WAAW;AAAA,EACb;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,QAAQ,CAAC,SAAS,GAAG,YAAY;AACxB,WAAA;AAAA,MACL,eAAe,CAAC,SAAS;AACvB,YACE,KAAK,OAAO,SAASC,MAAA,eAAe,cACpC,KAAK,OAAO,SAAS,iBACrB,KAAK,OAAO,SAASA,MAAe,eAAA,sBACpC,CAAC,QAAQ;AAAA,UACP,KAAK;AAAA,UACL;AAAA,QAAA,GAEF;AACA;AAAA,QACF;AAEM,cAAA,aAAaC,SAAAA,SAAS,oBAAoB,OAAO;AACjD,cAAA,0BAAyB,yCAAY,WAAU;AAErD,YACE,CAACA,SAAS,SAAA,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,SAASD,MAAAA,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;;;"}
@@ -1,3 +1,3 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
2
  export declare const name = "stable-query-client";
3
- export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.cjs","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,oBAAmB,IAAA,GAAGC,oBAAe;AAAA,EACtC,CAACC,uBAAsB,IAAA,GAAGC,uBAAkB;AAAA,EAC5C,CAACC,yBAAwB,IAAA,GAAGC,yBAAoB;AAClD;;"}
1
+ {"version":3,"file":"rules.cjs","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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>\n> = {\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":";;;;;AAKO,MAAM,QAGT;AAAA,EACF,CAACA,oBAAmB,IAAA,GAAGC,oBAAe;AAAA,EACtC,CAACC,uBAAsB,IAAA,GAAGC,uBAAkB;AAAA,EAC5C,CAACC,yBAAwB,IAAA,GAAGC,yBAAoB;AAClD;;"}
@@ -1,5 +1,2 @@
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
- };
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const rules: Record<string, ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>>;
@@ -169,7 +169,7 @@ const ASTUtils = {
169
169
  },
170
170
  getClosestVariableDeclarator(node) {
171
171
  let currentNode = node;
172
- while (currentNode !== void 0 && currentNode.type !== utils.AST_NODE_TYPES.Program) {
172
+ while (currentNode.type !== utils.AST_NODE_TYPES.Program) {
173
173
  if (currentNode.type === utils.AST_NODE_TYPES.VariableDeclarator) {
174
174
  return currentNode;
175
175
  }
@@ -1 +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,I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AA,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
+ {"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'\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<TSESLint.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<TSESLint.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 (currentNode.type !== AST_NODE_TYPES.Program) {\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":";;;;AAIO,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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- import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
4
3
  export declare const ASTUtils: {
5
4
  isNodeOfOneOf<T extends AST_NODE_TYPES>(node: TSESTree.Node, types: readonly T[]): node is TSESTree.Node & {
6
5
  type: T;
@@ -29,11 +28,11 @@ export declare const ASTUtils: {
29
28
  }): Array<TSESLint.Scope.Reference>;
30
29
  mapKeyNodeToText(node: TSESTree.Node, sourceCode: Readonly<TSESLint.SourceCode>): string;
31
30
  isValidReactComponentOrHookName(identifier: TSESTree.Identifier | null | undefined): boolean;
32
- getFunctionAncestor(context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
31
+ getFunctionAncestor(context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
33
32
  getReferencedExpressionByIdentifier(params: {
34
33
  node: TSESTree.Node;
35
- context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>;
34
+ context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>;
36
35
  }): TSESTree.Expression | null;
37
- getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.VariableDeclarator | undefined;
36
+ getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.LetOrConstOrVarDeclarator | undefined;
38
37
  getNestedReturnStatements(node: TSESTree.Node): Array<TSESTree.ReturnStatement>;
39
38
  };
@@ -3,5 +3,5 @@ import type { EnhancedCreate } from './detect-react-query-imports.cjs';
3
3
  type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
4
4
  create: EnhancedCreate;
5
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>;
6
+ export declare function createRule({ create, ...rest }: EslintRule): ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
7
7
  export {};
@@ -7,8 +7,7 @@ function detectTanstackQueryImports(create) {
7
7
  const helpers = {
8
8
  isSpecificTanstackQueryImport(node, source) {
9
9
  return !!tanstackQueryImportSpecifiers.find((specifier) => {
10
- var _a;
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) {
10
+ if (specifier.type === utils.TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === utils.TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
12
11
  return node.name === specifier.local.name;
13
12
  }
14
13
  return false;
@@ -1 +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,SAAS,uBAAuB;AACtC,UAAM,gCAA8D,CAAA;AAEpE,UAAM,UAAmB;AAAA,MACvB,8BAA8B,MAAM,QAAQ;AAC1C,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;;AACzD,cACE,UAAU,SAASA,MAAS,SAAA,eAAe,qBAC3C,eAAU,WAAV,mBAAkB,UAChBA,MAAAA,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,QAClC;AACO,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEO,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,MACA,sBAAsB,MAAM;AAC1B,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cAAI,UAAU,SAASA,eAAS,eAAe,iBAAiB;AACvD,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEO,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,IAAA;AAGF,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS,KACzB,KAAK,eAAe,WACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,QAAQ,GACnC;AAC8B,wCAAA,KAAK,GAAG,KAAK,UAAU;AAAA,QACvD;AAAA,MACF;AAAA,IAAA;AAIF,UAAM,mBAAmB,OAAO,SAAS,oBAAoB,OAAO;AACpE,UAAM,2BAAkD,CAAA;AAExD,UAAM,UAAU,IAAI;AAAA,MAClB,OAAO,KAAK,qBAAqB,EAAE,OAAO,OAAO,KAAK,gBAAgB,CAAC;AAAA,IAAA;AAKjE,YAAA,QAAQ,CAAC,gBAAgB;AACN,+BAAA,WAAW,IAAI,CAAC,SAAS;;AAChD,YAAI,eAAe,uBAAuB;AAClB,sCAAA,iBAAA,+CAAe;AAAA,QACvC;AAGI,YAAA,iBAAiB,WAAW,GAAG;AAC1B,kBAAA,sBAAiB,iBAAjB,0CAAgC;AAAA,QACzC;AAEO,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAEM,WAAA;AAAA,EAAA;AAEX;;"}
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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A,iBAAiB,WAAW,GAAG;AAC1B,kBAAA,sBAAiB,iBAAjB,0CAAgC;AAAA,QACzC;AAEO,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAEM,WAAA;AAAA,EAAA;AAEX;;"}
@@ -1,6 +1,7 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
1
2
  export declare const configs: {
2
3
  recommended: {
3
4
  plugins: string[];
4
- rules: Record<string, "error" | "strict" | "warn">;
5
+ rules: [string, TSESLint.RuleModule<any, any, TSESLint.RuleListener>];
5
6
  };
6
7
  };
@@ -1,6 +1,7 @@
1
1
  import { rules } from "./rules.js";
2
2
  function generateRecommendedConfig(allRules) {
3
3
  return Object.entries(allRules).reduce(
4
+ // @ts-expect-error
4
5
  (memo, [name, rule]) => {
5
6
  const { recommended } = rule.meta.docs || {};
6
7
  return {
@@ -1 +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;"}
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 // @ts-expect-error\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;AAAA,IAE9B,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;"}
@@ -1,3 +1,3 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
2
  export declare const name = "exhaustive-deps";
3
- export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -23,10 +23,10 @@ const rule = createRule({
23
23
  schema: []
24
24
  },
25
25
  defaultOptions: [],
26
- create(context) {
26
+ create: (context) => {
27
27
  return {
28
- Property(node) {
29
- if (node.parent === void 0 || !ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
28
+ Property: (node) => {
29
+ if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
30
30
  return;
31
31
  }
32
32
  const scopeManager = context.getSourceCode().scopeManager;
@@ -1 +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"],"names":[],"mappings":";;;;;AAOA,MAAM,YAAY;AAClB,MAAM,WAAW;AAEV,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,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;AACP,WAAA;AAAA,MACL,SAAS,MAAM;AACb,YACE,KAAK,WAAW,UAChB,CAAC,SAAS,mBAAmB,KAAK,MAAM,KACxC,CAAC,SAAS,qBAAqB,KAAK,KAAK,SAAS,GAClD;AACA;AAAA,QACF;AAEM,cAAA,eAAe,QAAQ,cAAA,EAAgB;AAC7C,cAAM,WAAW,SAAS;AAAA,UACxB,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAEF,cAAM,UAAU,SAAS;AAAA,UACvB,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAIA,YAAA,iBAAiB,QACjB,aAAa,UACb,YAAY,UACZ,QAAQ,MAAM,SAAS,eAAe,yBACtC;AACA;AAAA,QACF;AAEA,YAAI,eAAe,SAAS;AAG1B,YAAA,aAAa,SAAS,eAAe,kBACrC,aAAa,WAAW,SAAS,eAAe,i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ClE,KAAK,IAAI;AAEN,gBAAA,sBAAsB,WACzB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KAAK,aAAa,GAAG;AAEvC,gBAAM,cAAsD,CAAA;AAExD,cAAA,aAAa,SAAS,eAAe,iBAAiB;AACxD,wBAAY,KAAK;AAAA,cACf,WAAW;AAAA,cACX,MAAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACF,uBAAA,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;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
+ {"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 { ESLintUtils, TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error' as any,\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 !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"],"names":[],"mappings":";;;;;AAOA,MAAM,YAAY;AAClB,MAAM,WAAW;AAEV,MAAM,OAAO;AAEb,MAAM,OAIT,WAAW;AAAA,EACb;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,QAAQ,CAAC,YAAY;AACZ,WAAA;AAAA,MACL,UAAU,CAAC,SAAS;AAClB,YACE,CAAC,SAAS,mBAAmB,KAAK,MAAM,KACxC,CAAC,SAAS,qBAAqB,KAAK,KAAK,SAAS,GAClD;AACA;AAAA,QACF;AAEM,cAAA,eAAe,QAAQ,cAAA,EAAgB;AAC7C,cAAM,WAAW,SAAS;AAAA,UACxB,KAAK,OAAO;AAAA,UACZ;AAAA,QAAA;AAEF,cAAM,UAAU,SAAS;AAAA,UACvB,KAAK,OAAO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;AAAA,UAChB;AAAA,QACA,EAAA;AAEJ,cAAM,oBAAoB,SAAS,aAAa,CAAC,MAAM,EAAE,IAAI;AAEzD,YAAA,kBAAkB,SAAS,GAAG;AAChC,gBAAM,gBAAgB,kBACnB,IAAI,CAAC,QAAQ,SAAS,iBAAiB,IAAI,YAAY,UAAU,CAAC,EAClE,KAAK,IAAI;AAEN,gBAAA,sBAAsB,WACzB,QAAQ,aAAa,EACrB,QAAQ,OAAO,KAAK,aAAa,GAAG;AAEvC,gBAAM,cAAsD,CAAA;AAExD,cAAA,aAAa,SAAS,eAAe,iBAAiB;AACxD,wBAAY,KAAK;AAAA,cACf,WAAW;AAAA,cACX,MAAM,EAAE,QAAQ,oBAAoB;AAAA,cACpC,IAAI,OAAO;AACF,uBAAA,MAAM,YAAY,eAAe,mBAAmB;AAAA,cAC7D;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;"}
@@ -2,7 +2,6 @@ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
2
2
  import { ASTUtils } from "../utils/ast-utils.js";
3
3
  const ExhaustiveDepsUtils = {
4
4
  isRelevantReference(params) {
5
- var _a;
6
5
  const { reference, scopeManager, context } = params;
7
6
  const component = ASTUtils.getFunctionAncestor(context);
8
7
  if (component !== void 0 && !ASTUtils.isDeclaredInNode({
@@ -12,7 +11,7 @@ const ExhaustiveDepsUtils = {
12
11
  })) {
13
12
  return false;
14
13
  }
15
- return reference.identifier.name !== "undefined" && ((_a = reference.identifier.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
14
+ return reference.identifier.name !== "undefined" && reference.identifier.parent.type !== AST_NODE_TYPES.NewExpression && !ExhaustiveDepsUtils.isQueryClientReference(reference);
16
15
  },
17
16
  isQueryClientReference(reference) {
18
17
  var _a, _b, _c;
@@ -1 +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;"}
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,eAC9B,UAAU,WAAW,OAAO,SAAS,eAAe,iBACpD,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;"}
@@ -1,2 +1,3 @@
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
1
2
  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>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -18,11 +18,10 @@ const rule = createRule({
18
18
  schema: []
19
19
  },
20
20
  defaultOptions: [],
21
- create(context, _, helpers) {
21
+ create: (context, _, helpers) => {
22
22
  return {
23
- CallExpression(node) {
24
- var _a;
25
- if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || ((_a = node.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.VariableDeclarator) {
23
+ CallExpression: (node) => {
24
+ if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
26
25
  return;
27
26
  }
28
27
  const returnValue = node.parent.id;
@@ -1 +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;"}
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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Disallows rest destructuring in queries',\n recommended: 'warn' as any,\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":";;;;AAMO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,OAIT,WAAW;AAAA,EACb;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,QAAQ,CAAC,SAAS,GAAG,YAAY;AACxB,WAAA;AAAA,MACL,gBAAgB,CAAC,SAAS;AACxB,YACE,CAAC,SAAS,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,KAC1C,KAAK,OAAO,SAAS,eAAe,oBACpC;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;"}
@@ -1,3 +1,3 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
2
  export declare const name = "stable-query-client";
3
- export declare const rule: TSESLint.RuleModule<string, readonly unknown[], TSESLint.RuleListener>;
3
+ export declare const rule: ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>;
@@ -22,11 +22,10 @@ const rule = createRule({
22
22
  schema: []
23
23
  },
24
24
  defaultOptions: [],
25
- create(context, _, helpers) {
25
+ create: (context, _, helpers) => {
26
26
  return {
27
- NewExpression(node) {
28
- var _a;
29
- if (node.callee.type !== AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || ((_a = node.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
27
+ NewExpression: (node) => {
28
+ if (node.callee.type !== AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
30
29
  node.callee,
31
30
  "@tanstack/react-query"
32
31
  )) {
@@ -1 +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,M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H;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const name = 'stable-query-client'\n\nexport const rule: ESLintUtils.RuleModule<\n string,\n any,\n ESLintUtils.RuleListener\n> = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Makes sure that QueryClient is stable',\n recommended: 'error' as any,\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(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,QAAQ;AAAA,cAAA;AAAA,YACtD;AAAA,UACF,GACC;AAAA,QAAA,CACJ;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
@@ -1,5 +1,2 @@
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
- };
1
+ import type { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const rules: Record<string, ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>>;
@@ -1 +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
+ {"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'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>\n> = {\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":";;;AAKO,MAAM,QAGT;AAAA,EACF,CAACA,IAAmB,GAAGC;AAAAA,EACvB,CAACC,MAAsB,GAAGC;AAAAA,EAC1B,CAACC,MAAwB,GAAGC;AAC9B;"}
@@ -1,6 +1,5 @@
1
1
  import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
2
  import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
3
- import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
4
3
  export declare const ASTUtils: {
5
4
  isNodeOfOneOf<T extends AST_NODE_TYPES>(node: TSESTree.Node, types: readonly T[]): node is TSESTree.Node & {
6
5
  type: T;
@@ -29,11 +28,11 @@ export declare const ASTUtils: {
29
28
  }): Array<TSESLint.Scope.Reference>;
30
29
  mapKeyNodeToText(node: TSESTree.Node, sourceCode: Readonly<TSESLint.SourceCode>): string;
31
30
  isValidReactComponentOrHookName(identifier: TSESTree.Identifier | null | undefined): boolean;
32
- getFunctionAncestor(context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
31
+ getFunctionAncestor(context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
33
32
  getReferencedExpressionByIdentifier(params: {
34
33
  node: TSESTree.Node;
35
- context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>;
34
+ context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>;
36
35
  }): TSESTree.Expression | null;
37
- getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.VariableDeclarator | undefined;
36
+ getClosestVariableDeclarator(node: TSESTree.Node): TSESTree.LetOrConstOrVarDeclarator | undefined;
38
37
  getNestedReturnStatements(node: TSESTree.Node): Array<TSESTree.ReturnStatement>;
39
38
  };
@@ -167,7 +167,7 @@ const ASTUtils = {
167
167
  },
168
168
  getClosestVariableDeclarator(node) {
169
169
  let currentNode = node;
170
- while (currentNode !== void 0 && currentNode.type !== AST_NODE_TYPES.Program) {
170
+ while (currentNode.type !== AST_NODE_TYPES.Program) {
171
171
  if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {
172
172
  return currentNode;
173
173
  }
@@ -1 +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,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0B,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
+ {"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'\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<TSESLint.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<TSESLint.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 (currentNode.type !== AST_NODE_TYPES.Program) {\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":";;AAIO,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,MAAgD;AAClD,WAAA,KAAK,SAAS,eAAe;AAAA,EACtC;AAAA,EACA,mBAAmB,MAAwD;AAClE,WAAA,KAAK,SAAS,eAAe;AAAA,EACtC;AAAA,EACA,4BACE,MACA,KAC2B;AAEzB,WAAA,SAAS,WAAW,IAAI,KAAK,SAAS,qBAAqB,KAAK,KAAK,GAAG;AAAA,EAE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,KAAK,UAAU,QAAQ,CAAC,MAAM;AAC5B,yBAAiB,KAAK,GAAG,SAAS,0BAA0B,CAAC,CAAC;AAAA,MAAA,CAC/D,IACD,iBAAiB;AAAA,QACf,GAAG,SAAS,0BAA0B,KAAK,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;"}
@@ -3,5 +3,5 @@ import type { EnhancedCreate } from './detect-react-query-imports.js';
3
3
  type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
4
4
  create: EnhancedCreate;
5
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>;
6
+ export declare function createRule({ create, ...rest }: EslintRule): ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
7
7
  export {};
@@ -5,8 +5,7 @@ function detectTanstackQueryImports(create) {
5
5
  const helpers = {
6
6
  isSpecificTanstackQueryImport(node, source) {
7
7
  return !!tanstackQueryImportSpecifiers.find((specifier) => {
8
- var _a;
9
- if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && ((_a = specifier.parent) == null ? void 0 : _a.type) === TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
8
+ if (specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.parent.type === TSESTree.AST_NODE_TYPES.ImportDeclaration && specifier.parent.source.value === source) {
10
9
  return node.name === specifier.local.name;
11
10
  }
12
11
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"detect-react-query-imports.js","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":[],"mappings":";AAuBO,SAAS,2BAA2B,QAAgC;AAClE,SAAA,CAAC,SAAS,uBAAuB;AACtC,UAAM,gCAA8D,CAAA;AAEpE,UAAM,UAAmB;AAAA,MACvB,8BAA8B,MAAM,QAAQ;AAC1C,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;;AACzD,cACE,UAAU,SAAS,SAAS,eAAe,qBAC3C,eAAU,WAAV,mBAAkB,UAChB,SAAS,eAAe,qBAC1B,UAAU,OAAO,OAAO,UAAU,QAClC;AACO,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEO,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,MACA,sBAAsB,MAAM;AAC1B,eAAO,CAAC,CAAC,8BAA8B,KAAK,CAAC,cAAc;AACzD,cAAI,UAAU,SAAS,SAAS,eAAe,iBAAiB;AACvD,mBAAA,KAAK,SAAS,UAAU,MAAM;AAAA,UACvC;AAEO,iBAAA;AAAA,QAAA,CACR;AAAA,MACH;AAAA,IAAA;AAGF,UAAM,wBAA+C;AAAA,MACnD,kBAAkB,MAAM;AACtB,YACE,KAAK,WAAW,SAAS,KACzB,KAAK,eAAe,WACpB,KAAK,OAAO,MAAM,WAAW,YAAY,KACzC,KAAK,OAAO,MAAM,SAAS,QAAQ,GACnC;AAC8B,wCAAA,KAAK,GAAG,KAAK,UAAU;AAAA,QACvD;AAAA,MACF;AAAA,IAAA;AAIF,UAAM,mBAAmB,OAAO,SAAS,oBAAoB,OAAO;AACpE,UAAM,2BAAkD,CAAA;AAExD,UAAM,UAAU,IAAI;AAAA,MAClB,OAAO,KAAK,qBAAqB,EAAE,OAAO,OAAO,KAAK,gBAAgB,CAAC;AAAA,IAAA;AAKjE,YAAA,QAAQ,CAAC,gBAAgB;AACN,+BAAA,WAAW,IAAI,CAAC,SAAS;;AAChD,YAAI,eAAe,uBAAuB;AAClB,sCAAA,iBAAA,+CAAe;AAAA,QACvC;AAGI,YAAA,iBAAiB,WAAW,GAAG;AAC1B,kBAAA,sBAAiB,iBAAjB,0CAAgC;AAAA,QACzC;AAEO,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAEM,WAAA;AAAA,EAAA;AAEX;"}
1
+ {"version":3,"file":"detect-react-query-imports.js","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":[],"mappings":";AAuBO,SAAS,2BAA2B,QAAgC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,QACzC;AAEO,eAAA;AAAA,MAAA;AAAA,IACT,CACD;AAEM,WAAA;AAAA,EAAA;AAEX;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/eslint-plugin-query",
3
- "version": "5.18.0",
3
+ "version": "5.20.0",
4
4
  "description": "ESLint plugin for TanStack Query",
5
5
  "author": "Eliya Cohen",
6
6
  "license": "MIT",
@@ -36,9 +36,10 @@
36
36
  "src"
37
37
  ],
38
38
  "dependencies": {
39
- "@typescript-eslint/utils": "^5.62.0"
39
+ "@typescript-eslint/utils": "^6.20.0"
40
40
  },
41
41
  "devDependencies": {
42
+ "@typescript-eslint/rule-tester": "^6.20.0",
42
43
  "eslint": "^8.56.0"
43
44
  },
44
45
  "peerDependencies": {
@@ -1,8 +1,8 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils'
1
+ import { RuleTester } from '@typescript-eslint/rule-tester'
2
2
  import { normalizeIndent } from '../utils/test-utils'
3
3
  import { rule } from '../rules/exhaustive-deps.rule'
4
4
 
5
- const ruleTester = new ESLintUtils.RuleTester({
5
+ const ruleTester = new RuleTester({
6
6
  parser: '@typescript-eslint/parser',
7
7
  settings: {},
8
8
  })
package/src/configs.ts CHANGED
@@ -5,6 +5,7 @@ function generateRecommendedConfig(
5
5
  allRules: Record<string, TSESLint.RuleModule<any, any>>,
6
6
  ) {
7
7
  return Object.entries(allRules).reduce(
8
+ // @ts-expect-error
8
9
  (memo, [name, rule]) => {
9
10
  const { recommended } = rule.meta.docs || {}
10
11
 
@@ -3,20 +3,24 @@ import { ASTUtils } from '../utils/ast-utils'
3
3
  import { createRule } from '../utils/create-rule'
4
4
  import { uniqueBy } from '../utils/unique-by'
5
5
  import { ExhaustiveDepsUtils } from './exhaustive-deps.utils'
6
- import type { TSESLint } from '@typescript-eslint/utils'
6
+ import type { ESLintUtils, TSESLint } from '@typescript-eslint/utils'
7
7
 
8
8
  const QUERY_KEY = 'queryKey'
9
9
  const QUERY_FN = 'queryFn'
10
10
 
11
11
  export const name = 'exhaustive-deps'
12
12
 
13
- export const rule = createRule({
13
+ export const rule: ESLintUtils.RuleModule<
14
+ string,
15
+ any,
16
+ ESLintUtils.RuleListener
17
+ > = createRule({
14
18
  name,
15
19
  meta: {
16
20
  type: 'problem',
17
21
  docs: {
18
22
  description: 'Exhaustive deps rule for useQuery',
19
- recommended: 'error',
23
+ recommended: 'error' as any,
20
24
  },
21
25
  messages: {
22
26
  missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,
@@ -28,11 +32,10 @@ export const rule = createRule({
28
32
  },
29
33
  defaultOptions: [],
30
34
 
31
- create(context) {
35
+ create: (context) => {
32
36
  return {
33
- Property(node) {
37
+ Property: (node) => {
34
38
  if (
35
- node.parent === undefined ||
36
39
  !ASTUtils.isObjectExpression(node.parent) ||
37
40
  !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)
38
41
  ) {
@@ -24,7 +24,7 @@ export const ExhaustiveDepsUtils = {
24
24
 
25
25
  return (
26
26
  reference.identifier.name !== 'undefined' &&
27
- reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression &&
27
+ reference.identifier.parent.type !== AST_NODE_TYPES.NewExpression &&
28
28
  !ExhaustiveDepsUtils.isQueryClientReference(reference)
29
29
  )
30
30
  },
@@ -2,18 +2,23 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
2
2
  import { createRule } from '../../utils/create-rule'
3
3
  import { ASTUtils } from '../../utils/ast-utils'
4
4
  import { NoRestDestructuringUtils } from './no-rest-destructuring.utils'
5
+ import type { ESLintUtils } from '@typescript-eslint/utils'
5
6
 
6
7
  export const name = 'no-rest-destructuring'
7
8
 
8
9
  const queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']
9
10
 
10
- export const rule = createRule({
11
+ export const rule: ESLintUtils.RuleModule<
12
+ string,
13
+ any,
14
+ ESLintUtils.RuleListener
15
+ > = createRule({
11
16
  name,
12
17
  meta: {
13
18
  type: 'problem',
14
19
  docs: {
15
20
  description: 'Disallows rest destructuring in queries',
16
- recommended: 'warn',
21
+ recommended: 'warn' as any,
17
22
  },
18
23
  messages: {
19
24
  objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`,
@@ -22,13 +27,13 @@ export const rule = createRule({
22
27
  },
23
28
  defaultOptions: [],
24
29
 
25
- create(context, _, helpers) {
30
+ create: (context, _, helpers) => {
26
31
  return {
27
- CallExpression(node) {
32
+ CallExpression: (node) => {
28
33
  if (
29
34
  !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||
30
35
  !helpers.isTanstackQueryImport(node.callee) ||
31
- node.parent?.type !== AST_NODE_TYPES.VariableDeclarator
36
+ node.parent.type !== AST_NODE_TYPES.VariableDeclarator
32
37
  ) {
33
38
  return
34
39
  }
@@ -1,8 +1,8 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils'
1
+ import { RuleTester } from '@typescript-eslint/rule-tester'
2
2
  import { normalizeIndent } from '../../utils/test-utils'
3
3
  import { rule } from './no-rest-destructuring.rule'
4
4
 
5
- const ruleTester = new ESLintUtils.RuleTester({
5
+ const ruleTester = new RuleTester({
6
6
  parser: '@typescript-eslint/parser',
7
7
  settings: {},
8
8
  })
@@ -2,16 +2,21 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'
2
2
  import { ASTUtils } from '../../utils/ast-utils'
3
3
  import { createRule } from '../../utils/create-rule'
4
4
  import type { TSESLint } from '@typescript-eslint/utils'
5
+ import type { ESLintUtils } from '@typescript-eslint/utils'
5
6
 
6
7
  export const name = 'stable-query-client'
7
8
 
8
- export const rule = createRule({
9
+ export const rule: ESLintUtils.RuleModule<
10
+ string,
11
+ any,
12
+ ESLintUtils.RuleListener
13
+ > = createRule({
9
14
  name,
10
15
  meta: {
11
16
  type: 'problem',
12
17
  docs: {
13
18
  description: 'Makes sure that QueryClient is stable',
14
- recommended: 'error',
19
+ recommended: 'error' as any,
15
20
  },
16
21
  messages: {
17
22
  unstable: [
@@ -26,13 +31,13 @@ export const rule = createRule({
26
31
  },
27
32
  defaultOptions: [],
28
33
 
29
- create(context, _, helpers) {
34
+ create: (context, _, helpers) => {
30
35
  return {
31
- NewExpression(node) {
36
+ NewExpression: (node) => {
32
37
  if (
33
38
  node.callee.type !== AST_NODE_TYPES.Identifier ||
34
39
  node.callee.name !== 'QueryClient' ||
35
- node.parent?.type !== AST_NODE_TYPES.VariableDeclarator ||
40
+ node.parent.type !== AST_NODE_TYPES.VariableDeclarator ||
36
41
  !helpers.isSpecificTanstackQueryImport(
37
42
  node.callee,
38
43
  '@tanstack/react-query',
@@ -1,8 +1,8 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils'
1
+ import { RuleTester } from '@typescript-eslint/rule-tester'
2
2
  import { normalizeIndent } from '../../utils/test-utils'
3
3
  import { rule } from './stable-query-client.rule'
4
4
 
5
- const ruleTester = new ESLintUtils.RuleTester({
5
+ const ruleTester = new RuleTester({
6
6
  parser: '@typescript-eslint/parser',
7
7
  settings: {},
8
8
  })
package/src/rules.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import * as exhaustiveDeps from './rules/exhaustive-deps.rule'
2
2
  import * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'
3
3
  import * as noRestDestructuring from './rules/no-rest-desctructuring/no-rest-destructuring.rule'
4
+ import type { ESLintUtils } from '@typescript-eslint/utils'
4
5
 
5
- export const rules = {
6
+ export const rules: Record<
7
+ string,
8
+ ESLintUtils.RuleModule<string, any, ESLintUtils.RuleListener>
9
+ > = {
6
10
  [exhaustiveDeps.name]: exhaustiveDeps.rule,
7
11
  [stableQueryClient.name]: stableQueryClient.rule,
8
12
  [noRestDestructuring.name]: noRestDestructuring.rule,
@@ -1,7 +1,6 @@
1
1
  import { AST_NODE_TYPES } from '@typescript-eslint/utils'
2
2
  import { uniqueBy } from './unique-by'
3
3
  import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
4
- import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'
5
4
 
6
5
  export const ASTUtils = {
7
6
  isNodeOfOneOf<T extends AST_NODE_TYPES>(
@@ -212,7 +211,7 @@ export const ASTUtils = {
212
211
  )
213
212
  },
214
213
  getFunctionAncestor(
215
- context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>,
214
+ context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>,
216
215
  ) {
217
216
  for (const ancestor of context.getAncestors()) {
218
217
  if (ancestor.type === AST_NODE_TYPES.FunctionDeclaration) {
@@ -236,7 +235,7 @@ export const ASTUtils = {
236
235
  },
237
236
  getReferencedExpressionByIdentifier(params: {
238
237
  node: TSESTree.Node
239
- context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>
238
+ context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>
240
239
  }) {
241
240
  const { node, context } = params
242
241
 
@@ -254,10 +253,7 @@ export const ASTUtils = {
254
253
  getClosestVariableDeclarator(node: TSESTree.Node) {
255
254
  let currentNode: TSESTree.Node | undefined = node
256
255
 
257
- while (
258
- currentNode !== undefined &&
259
- currentNode.type !== AST_NODE_TYPES.Program
260
- ) {
256
+ while (currentNode.type !== AST_NODE_TYPES.Program) {
261
257
  if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {
262
258
  return currentNode
263
259
  }
@@ -30,7 +30,7 @@ export function detectTanstackQueryImports(create: EnhancedCreate): Create {
30
30
  return !!tanstackQueryImportSpecifiers.find((specifier) => {
31
31
  if (
32
32
  specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&
33
- specifier.parent?.type ===
33
+ specifier.parent.type ===
34
34
  TSESTree.AST_NODE_TYPES.ImportDeclaration &&
35
35
  specifier.parent.source.value === source
36
36
  ) {