@tanstack/eslint-plugin-query 5.67.2 → 5.68.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.
@@ -30,22 +30,29 @@ const rule = createRule({
30
30
  },
31
31
  defaultOptions: [],
32
32
  create: detectReactQueryImports.detectTanstackQueryImports((context, _, helpers) => {
33
+ const queryResultVariables = /* @__PURE__ */ new Set();
33
34
  return {
34
35
  CallExpression: (node) => {
35
- if (!astUtils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator) {
36
+ if (!astUtils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator || !helpers.isTanstackQueryImport(node.callee)) {
36
37
  return;
37
38
  }
38
39
  const returnValue = node.parent.id;
39
40
  if (node.callee.name !== "useQueries" && node.callee.name !== "useSuspenseQueries") {
40
41
  if (noRestDestructuring_utils.NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
41
- context.report({
42
+ return context.report({
42
43
  node: node.parent,
43
44
  messageId: "objectRestDestructure"
44
45
  });
45
46
  }
47
+ if (returnValue.type === utils.AST_NODE_TYPES.Identifier) {
48
+ queryResultVariables.add(returnValue.name);
49
+ }
46
50
  return;
47
51
  }
48
52
  if (returnValue.type !== utils.AST_NODE_TYPES.ArrayPattern) {
53
+ if (returnValue.type === utils.AST_NODE_TYPES.Identifier) {
54
+ queryResultVariables.add(returnValue.name);
55
+ }
49
56
  return;
50
57
  }
51
58
  returnValue.elements.forEach((queryResult) => {
@@ -59,6 +66,23 @@ const rule = createRule({
59
66
  });
60
67
  }
61
68
  });
69
+ },
70
+ VariableDeclarator: (node) => {
71
+ var _a;
72
+ if (((_a = node.init) == null ? void 0 : _a.type) === utils.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.init.name) && noRestDestructuring_utils.NoRestDestructuringUtils.isObjectRestDestructuring(node.id)) {
73
+ context.report({
74
+ node,
75
+ messageId: "objectRestDestructure"
76
+ });
77
+ }
78
+ },
79
+ SpreadElement: (node) => {
80
+ if (node.argument.type === utils.AST_NODE_TYPES.Identifier && queryResultVariables.has(node.argument.name)) {
81
+ context.report({
82
+ node,
83
+ messageId: "objectRestDestructure"
84
+ });
85
+ }
62
86
  }
63
87
  };
64
88
  })
@@ -1 +1 @@
1
- {"version":3,"file":"no-rest-destructuring.rule.cjs","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport { NoRestDestructuringUtils } from './no-rest-destructuring.utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = [\n 'useQuery',\n 'useQueries',\n 'useInfiniteQuery',\n 'useSuspenseQuery',\n 'useSuspenseQueries',\n 'useSuspenseInfiniteQuery',\n]\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\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: detectTanstackQueryImports((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 (\n node.callee.name !== 'useQueries' &&\n node.callee.name !== 'useSuspenseQueries'\n ) {\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":["ESLintUtils","getDocsUrl","detectTanstackQueryImports","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;;AAOO,MAAM,OAAO;AAEpB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAaA,MAAAA,YAAY,YAA2BC,qBAAU;AAE7D,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,CAAA;AAAA,EACV;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,QAAQC,wBAAAA,2BAA2B,CAAC,SAAS,GAAG,YAAY;AACnD,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,QAAA;AAGI,cAAA,cAAc,KAAK,OAAO;AAChC,YACE,KAAK,OAAO,SAAS,gBACrB,KAAK,OAAO,SAAS,sBACrB;AACI,cAAAC,0BAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YAAA,CACZ;AAAA,UAAA;AAEH;AAAA,QAAA;AAGE,YAAA,YAAY,SAASD,MAAA,eAAe,cAAc;AACpD;AAAA,QAAA;AAEU,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UAAA;AAEE,cAAAC,0BAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YAAA,CACZ;AAAA,UAAA;AAAA,QACH,CACD;AAAA,MAAA;AAAA,IAEL;AAAA,EACD,CAAA;AACH,CAAC;;;"}
1
+ {"version":3,"file":"no-rest-destructuring.rule.cjs","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport { NoRestDestructuringUtils } from './no-rest-destructuring.utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = [\n 'useQuery',\n 'useQueries',\n 'useInfiniteQuery',\n 'useSuspenseQuery',\n 'useSuspenseQueries',\n 'useSuspenseInfiniteQuery',\n]\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\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: detectTanstackQueryImports((context, _, helpers) => {\n const queryResultVariables = new Set<string>()\n\n return {\n CallExpression: (node) => {\n if (\n !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||\n node.parent.type !== AST_NODE_TYPES.VariableDeclarator ||\n !helpers.isTanstackQueryImport(node.callee)\n ) {\n return\n }\n\n const returnValue = node.parent.id\n\n if (\n node.callee.name !== 'useQueries' &&\n node.callee.name !== 'useSuspenseQueries'\n ) {\n if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {\n return context.report({\n node: node.parent,\n messageId: 'objectRestDestructure',\n })\n }\n\n if (returnValue.type === AST_NODE_TYPES.Identifier) {\n queryResultVariables.add(returnValue.name)\n }\n\n return\n }\n\n if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {\n if (returnValue.type === AST_NODE_TYPES.Identifier) {\n queryResultVariables.add(returnValue.name)\n }\n return\n }\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 VariableDeclarator: (node) => {\n if (\n node.init?.type === AST_NODE_TYPES.Identifier &&\n queryResultVariables.has(node.init.name) &&\n NoRestDestructuringUtils.isObjectRestDestructuring(node.id)\n ) {\n context.report({\n node,\n messageId: 'objectRestDestructure',\n })\n }\n },\n\n SpreadElement: (node) => {\n if (\n node.argument.type === AST_NODE_TYPES.Identifier &&\n queryResultVariables.has(node.argument.name)\n ) {\n context.report({\n node,\n messageId: 'objectRestDestructure',\n })\n }\n },\n }\n }),\n})\n"],"names":["ESLintUtils","getDocsUrl","detectTanstackQueryImports","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;;AAOO,MAAM,OAAO;AAEpB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAaA,MAAAA,YAAY,YAA2BC,qBAAU;AAE7D,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AA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K,SAAL,mBAAW,UAASD,MAAAA,eAAe,cACnC,qBAAqB,IAAI,KAAK,KAAK,IAAI,KACvCC,0BAAAA,yBAAyB,0BAA0B,KAAK,EAAE,GAC1D;AACA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,UAAA,CACZ;AAAA,QAAA;AAAA,MAEL;AAAA,MAEA,eAAe,CAAC,SAAS;AAErB,YAAA,KAAK,SAAS,SAASD,qBAAe,cACtC,qBAAqB,IAAI,KAAK,SAAS,IAAI,GAC3C;AACA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,UAAA,CACZ;AAAA,QAAA;AAAA,MACH;AAAA,IAEJ;AAAA,EACD,CAAA;AACH,CAAC;;;"}
@@ -28,22 +28,29 @@ const rule = createRule({
28
28
  },
29
29
  defaultOptions: [],
30
30
  create: detectTanstackQueryImports((context, _, helpers) => {
31
+ const queryResultVariables = /* @__PURE__ */ new Set();
31
32
  return {
32
33
  CallExpression: (node) => {
33
- if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
34
+ if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || node.parent.type !== AST_NODE_TYPES.VariableDeclarator || !helpers.isTanstackQueryImport(node.callee)) {
34
35
  return;
35
36
  }
36
37
  const returnValue = node.parent.id;
37
38
  if (node.callee.name !== "useQueries" && node.callee.name !== "useSuspenseQueries") {
38
39
  if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
39
- context.report({
40
+ return context.report({
40
41
  node: node.parent,
41
42
  messageId: "objectRestDestructure"
42
43
  });
43
44
  }
45
+ if (returnValue.type === AST_NODE_TYPES.Identifier) {
46
+ queryResultVariables.add(returnValue.name);
47
+ }
44
48
  return;
45
49
  }
46
50
  if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {
51
+ if (returnValue.type === AST_NODE_TYPES.Identifier) {
52
+ queryResultVariables.add(returnValue.name);
53
+ }
47
54
  return;
48
55
  }
49
56
  returnValue.elements.forEach((queryResult) => {
@@ -57,6 +64,23 @@ const rule = createRule({
57
64
  });
58
65
  }
59
66
  });
67
+ },
68
+ VariableDeclarator: (node) => {
69
+ var _a;
70
+ if (((_a = node.init) == null ? void 0 : _a.type) === AST_NODE_TYPES.Identifier && queryResultVariables.has(node.init.name) && NoRestDestructuringUtils.isObjectRestDestructuring(node.id)) {
71
+ context.report({
72
+ node,
73
+ messageId: "objectRestDestructure"
74
+ });
75
+ }
76
+ },
77
+ SpreadElement: (node) => {
78
+ if (node.argument.type === AST_NODE_TYPES.Identifier && queryResultVariables.has(node.argument.name)) {
79
+ context.report({
80
+ node,
81
+ messageId: "objectRestDestructure"
82
+ });
83
+ }
60
84
  }
61
85
  };
62
86
  })
@@ -1 +1 @@
1
- {"version":3,"file":"no-rest-destructuring.rule.js","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport { NoRestDestructuringUtils } from './no-rest-destructuring.utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = [\n 'useQuery',\n 'useQueries',\n 'useInfiniteQuery',\n 'useSuspenseQuery',\n 'useSuspenseQueries',\n 'useSuspenseInfiniteQuery',\n]\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\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: detectTanstackQueryImports((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 (\n node.callee.name !== 'useQueries' &&\n node.callee.name !== 'useSuspenseQueries'\n ) {\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":";;;;;AAOO,MAAM,OAAO;AAEpB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAa,YAAY,YAA2B,UAAU;AAE7D,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,CAAA;AAAA,EACV;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,QAAQ,2BAA2B,CAAC,SAAS,GAAG,YAAY;AACnD,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,QAAA;AAGI,cAAA,cAAc,KAAK,OAAO;AAChC,YACE,KAAK,OAAO,SAAS,gBACrB,KAAK,OAAO,SAAS,sBACrB;AACI,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YAAA,CACZ;AAAA,UAAA;AAEH;AAAA,QAAA;AAGE,YAAA,YAAY,SAAS,eAAe,cAAc;AACpD;AAAA,QAAA;AAEU,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UAAA;AAEE,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YAAA,CACZ;AAAA,UAAA;AAAA,QACH,CACD;AAAA,MAAA;AAAA,IAEL;AAAA,EACD,CAAA;AACH,CAAC;"}
1
+ {"version":3,"file":"no-rest-destructuring.rule.js","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport { NoRestDestructuringUtils } from './no-rest-destructuring.utils'\nimport type { ExtraRuleDocs } from '../../types'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = [\n 'useQuery',\n 'useQueries',\n 'useInfiniteQuery',\n 'useSuspenseQuery',\n 'useSuspenseQueries',\n 'useSuspenseInfiniteQuery',\n]\n\nconst createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)\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: detectTanstackQueryImports((context, _, helpers) => {\n const queryResultVariables = new Set<string>()\n\n return {\n CallExpression: (node) => {\n if (\n !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||\n node.parent.type !== AST_NODE_TYPES.VariableDeclarator ||\n !helpers.isTanstackQueryImport(node.callee)\n ) {\n return\n }\n\n const returnValue = node.parent.id\n\n if (\n node.callee.name !== 'useQueries' &&\n node.callee.name !== 'useSuspenseQueries'\n ) {\n if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {\n return context.report({\n node: node.parent,\n messageId: 'objectRestDestructure',\n })\n }\n\n if (returnValue.type === AST_NODE_TYPES.Identifier) {\n queryResultVariables.add(returnValue.name)\n }\n\n return\n }\n\n if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {\n if (returnValue.type === AST_NODE_TYPES.Identifier) {\n queryResultVariables.add(returnValue.name)\n }\n return\n }\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 VariableDeclarator: (node) => {\n if (\n node.init?.type === AST_NODE_TYPES.Identifier &&\n queryResultVariables.has(node.init.name) &&\n NoRestDestructuringUtils.isObjectRestDestructuring(node.id)\n ) {\n context.report({\n node,\n messageId: 'objectRestDestructure',\n })\n }\n },\n\n SpreadElement: (node) => {\n if (\n node.argument.type === AST_NODE_TYPES.Identifier &&\n queryResultVariables.has(node.argument.name)\n ) {\n context.report({\n node,\n messageId: 'objectRestDestructure',\n })\n }\n },\n }\n }),\n})\n"],"names":[],"mappings":";;;;;AAOO,MAAM,OAAO;AAEpB,MAAM,aAAa;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,aAAa,YAAY,YAA2B,UAAU;AAE7D,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,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mBAAW,UAAS,eAAe,cACnC,qBAAqB,IAAI,KAAK,KAAK,IAAI,KACvC,yBAAyB,0BAA0B,KAAK,EAAE,GAC1D;AACA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,UAAA,CACZ;AAAA,QAAA;AAAA,MAEL;AAAA,MAEA,eAAe,CAAC,SAAS;AAErB,YAAA,KAAK,SAAS,SAAS,eAAe,cACtC,qBAAqB,IAAI,KAAK,SAAS,IAAI,GAC3C;AACA,kBAAQ,OAAO;AAAA,YACb;AAAA,YACA,WAAW;AAAA,UAAA,CACZ;AAAA,QAAA;AAAA,MACH;AAAA,IAEJ;AAAA,EACD,CAAA;AACH,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/eslint-plugin-query",
3
- "version": "5.67.2",
3
+ "version": "5.68.0",
4
4
  "description": "ESLint plugin for TanStack Query",
5
5
  "author": "Eliya Cohen",
6
6
  "license": "MIT",
@@ -34,33 +34,45 @@ export const rule = createRule({
34
34
  defaultOptions: [],
35
35
 
36
36
  create: detectTanstackQueryImports((context, _, helpers) => {
37
+ const queryResultVariables = new Set<string>()
38
+
37
39
  return {
38
40
  CallExpression: (node) => {
39
41
  if (
40
42
  !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||
41
- !helpers.isTanstackQueryImport(node.callee) ||
42
- node.parent.type !== AST_NODE_TYPES.VariableDeclarator
43
+ node.parent.type !== AST_NODE_TYPES.VariableDeclarator ||
44
+ !helpers.isTanstackQueryImport(node.callee)
43
45
  ) {
44
46
  return
45
47
  }
46
48
 
47
49
  const returnValue = node.parent.id
50
+
48
51
  if (
49
52
  node.callee.name !== 'useQueries' &&
50
53
  node.callee.name !== 'useSuspenseQueries'
51
54
  ) {
52
55
  if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
53
- context.report({
56
+ return context.report({
54
57
  node: node.parent,
55
58
  messageId: 'objectRestDestructure',
56
59
  })
57
60
  }
61
+
62
+ if (returnValue.type === AST_NODE_TYPES.Identifier) {
63
+ queryResultVariables.add(returnValue.name)
64
+ }
65
+
58
66
  return
59
67
  }
60
68
 
61
69
  if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {
70
+ if (returnValue.type === AST_NODE_TYPES.Identifier) {
71
+ queryResultVariables.add(returnValue.name)
72
+ }
62
73
  return
63
74
  }
75
+
64
76
  returnValue.elements.forEach((queryResult) => {
65
77
  if (queryResult === null) {
66
78
  return
@@ -73,6 +85,31 @@ export const rule = createRule({
73
85
  }
74
86
  })
75
87
  },
88
+
89
+ VariableDeclarator: (node) => {
90
+ if (
91
+ node.init?.type === AST_NODE_TYPES.Identifier &&
92
+ queryResultVariables.has(node.init.name) &&
93
+ NoRestDestructuringUtils.isObjectRestDestructuring(node.id)
94
+ ) {
95
+ context.report({
96
+ node,
97
+ messageId: 'objectRestDestructure',
98
+ })
99
+ }
100
+ },
101
+
102
+ SpreadElement: (node) => {
103
+ if (
104
+ node.argument.type === AST_NODE_TYPES.Identifier &&
105
+ queryResultVariables.has(node.argument.name)
106
+ ) {
107
+ context.report({
108
+ node,
109
+ messageId: 'objectRestDestructure',
110
+ })
111
+ }
112
+ },
76
113
  }
77
114
  }),
78
115
  })