@tanstack/eslint-plugin-query 5.0.0 → 5.6.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.
- package/build/legacy/__tests__/configs.test.cjs +5 -3
- package/build/legacy/__tests__/configs.test.cjs.map +1 -1
- package/build/legacy/__tests__/configs.test.js +2 -0
- package/build/legacy/__tests__/configs.test.js.map +1 -1
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs +87 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs.map +1 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.cts +6 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.ts +6 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.js +61 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.rule.js.map +1 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.cjs +197 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.cjs.map +1 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.d.cts +2 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.d.ts +2 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.js +195 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.test.js.map +1 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs +39 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs.map +1 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.cts +7 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.d.ts +7 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.js +14 -0
- package/build/legacy/rules/no-rest-desctructuring/no-rest-destructuring.utils.js.map +1 -0
- package/build/legacy/rules.cjs +5 -3
- package/build/legacy/rules.cjs.map +1 -1
- package/build/legacy/rules.d.cts +1 -0
- package/build/legacy/rules.d.ts +1 -0
- package/build/legacy/rules.js +3 -1
- package/build/legacy/rules.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/configs.test.ts +2 -0
- package/src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts +64 -0
- package/src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts +195 -0
- package/src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts +11 -0
- package/src/rules.ts +2 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
// src/__tests__/configs.test.ts
|
|
4
|
+
var import_vitest = require("vitest.cjs");
|
|
4
5
|
var import_configs = require("../configs.cjs");
|
|
5
|
-
describe("configs", () => {
|
|
6
|
-
it("should match snapshot", () => {
|
|
7
|
-
expect(import_configs.configs).toMatchInlineSnapshot(`
|
|
6
|
+
(0, import_vitest.describe)("configs", () => {
|
|
7
|
+
(0, import_vitest.it)("should match snapshot", () => {
|
|
8
|
+
(0, import_vitest.expect)(import_configs.configs).toMatchInlineSnapshot(`
|
|
8
9
|
{
|
|
9
10
|
"recommended": {
|
|
10
11
|
"plugins": [
|
|
@@ -12,6 +13,7 @@ describe("configs", () => {
|
|
|
12
13
|
],
|
|
13
14
|
"rules": {
|
|
14
15
|
"@tanstack/query/exhaustive-deps": "error",
|
|
16
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
15
17
|
"@tanstack/query/stable-query-client": "error",
|
|
16
18
|
},
|
|
17
19
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/__tests__/configs.test.ts"],"sourcesContent":["import { configs } from '../configs'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n \"@tanstack/query/stable-query-client\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";;;AAAA,qBAAwB;
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/configs.test.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\nimport { configs } from '../configs'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n \"@tanstack/query/no-rest-destructuring\": \"warn\",\n \"@tanstack/query/stable-query-client\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";;;AAAA,oBAAqC;AACrC,qBAAwB;AAAA,IAExB,wBAAS,WAAW,MAAM;AACxB,wBAAG,yBAAyB,MAAM;AAChC,8BAAO,sBAAO,EAAE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAarC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/__tests__/configs.test.ts
|
|
2
|
+
import { describe, expect, it } from "vitest.js";
|
|
2
3
|
import { configs } from "../configs.js";
|
|
3
4
|
describe("configs", () => {
|
|
4
5
|
it("should match snapshot", () => {
|
|
@@ -10,6 +11,7 @@ describe("configs", () => {
|
|
|
10
11
|
],
|
|
11
12
|
"rules": {
|
|
12
13
|
"@tanstack/query/exhaustive-deps": "error",
|
|
14
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
13
15
|
"@tanstack/query/stable-query-client": "error",
|
|
14
16
|
},
|
|
15
17
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/__tests__/configs.test.ts"],"sourcesContent":["import { configs } from '../configs'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n \"@tanstack/query/stable-query-client\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,yBAAyB,MAAM;AAChC,WAAO,OAAO,EAAE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/configs.test.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\nimport { configs } from '../configs'\n\ndescribe('configs', () => {\n it('should match snapshot', () => {\n expect(configs).toMatchInlineSnapshot(`\n {\n \"recommended\": {\n \"plugins\": [\n \"@tanstack/eslint-plugin-query\",\n ],\n \"rules\": {\n \"@tanstack/query/exhaustive-deps\": \"error\",\n \"@tanstack/query/no-rest-destructuring\": \"warn\",\n \"@tanstack/query/stable-query-client\": \"error\",\n },\n },\n }\n `)\n })\n})\n"],"mappings":";AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,eAAe;AAExB,SAAS,WAAW,MAAM;AACxB,KAAG,yBAAyB,MAAM;AAChC,WAAO,OAAO,EAAE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAarC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts
|
|
21
|
+
var no_rest_destructuring_rule_exports = {};
|
|
22
|
+
__export(no_rest_destructuring_rule_exports, {
|
|
23
|
+
name: () => name,
|
|
24
|
+
rule: () => rule
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(no_rest_destructuring_rule_exports);
|
|
27
|
+
var import_utils = require("@typescript-eslint/utils");
|
|
28
|
+
var import_create_rule = require("../../utils/create-rule.cjs");
|
|
29
|
+
var import_ast_utils = require("../../utils/ast-utils.cjs");
|
|
30
|
+
var import_no_rest_destructuring = require("./no-rest-destructuring.utils.cjs");
|
|
31
|
+
var name = "no-rest-destructuring";
|
|
32
|
+
var queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
|
|
33
|
+
var rule = (0, import_create_rule.createRule)({
|
|
34
|
+
name,
|
|
35
|
+
meta: {
|
|
36
|
+
type: "problem",
|
|
37
|
+
docs: {
|
|
38
|
+
description: "Disallows rest destructuring in queries",
|
|
39
|
+
recommended: "warn"
|
|
40
|
+
},
|
|
41
|
+
messages: {
|
|
42
|
+
objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
|
|
43
|
+
},
|
|
44
|
+
schema: []
|
|
45
|
+
},
|
|
46
|
+
defaultOptions: [],
|
|
47
|
+
create(context, _, helpers) {
|
|
48
|
+
return {
|
|
49
|
+
CallExpression(node) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (!import_ast_utils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || ((_a = node.parent) == null ? void 0 : _a.type) !== import_utils.AST_NODE_TYPES.VariableDeclarator) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const returnValue = node.parent.id;
|
|
55
|
+
if (node.callee.name !== "useQueries") {
|
|
56
|
+
if (import_no_rest_destructuring.NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
|
|
57
|
+
context.report({
|
|
58
|
+
node: node.parent,
|
|
59
|
+
messageId: "objectRestDestructure"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (returnValue.type !== import_utils.AST_NODE_TYPES.ArrayPattern) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
returnValue.elements.forEach((queryResult) => {
|
|
68
|
+
if (queryResult === null) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (import_no_rest_destructuring.NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
|
|
72
|
+
context.report({
|
|
73
|
+
node: queryResult,
|
|
74
|
+
messageId: "objectRestDestructure"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
name,
|
|
85
|
+
rule
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=no-rest-destructuring.rule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,yBAA2B;AAC3B,uBAAyB;AACzB,mCAAyC;AAElC,IAAM,OAAO;AAEpB,IAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,IAAM,WAAO,+BAAW;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;AAC1B,WAAO;AAAA,MACL,eAAe,MAAM;AA1B3B;AA2BQ,YACE,CAAC,0BAAS,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAAS,4BAAe,oBACrC;AACA;AAAA,QACF;AAEA,cAAM,cAAc,KAAK,OAAO;AAChC,YAAI,KAAK,OAAO,SAAS,cAAc;AACrC,cAAI,sDAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YACb,CAAC;AAAA,UACH;AACA;AAAA,QACF;AAEA,YAAI,YAAY,SAAS,4BAAe,cAAc;AACpD;AAAA,QACF;AACA,oBAAY,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACA,cAAI,sDAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YACb,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
|
|
2
|
+
|
|
3
|
+
declare const name = "no-rest-destructuring";
|
|
4
|
+
declare const rule: _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
5
|
+
|
|
6
|
+
export { name, rule };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
|
|
2
|
+
|
|
3
|
+
declare const name = "no-rest-destructuring";
|
|
4
|
+
declare const rule: _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
5
|
+
|
|
6
|
+
export { name, rule };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.rule.ts
|
|
2
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
3
|
+
import { createRule } from "../../utils/create-rule.js";
|
|
4
|
+
import { ASTUtils } from "../../utils/ast-utils.js";
|
|
5
|
+
import { NoRestDestructuringUtils } from "./no-rest-destructuring.utils.js";
|
|
6
|
+
var name = "no-rest-destructuring";
|
|
7
|
+
var queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
|
|
8
|
+
var rule = createRule({
|
|
9
|
+
name,
|
|
10
|
+
meta: {
|
|
11
|
+
type: "problem",
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Disallows rest destructuring in queries",
|
|
14
|
+
recommended: "warn"
|
|
15
|
+
},
|
|
16
|
+
messages: {
|
|
17
|
+
objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`
|
|
18
|
+
},
|
|
19
|
+
schema: []
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context, _, helpers) {
|
|
23
|
+
return {
|
|
24
|
+
CallExpression(node) {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || ((_a = node.parent) == null ? void 0 : _a.type) !== AST_NODE_TYPES.VariableDeclarator) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const returnValue = node.parent.id;
|
|
30
|
+
if (node.callee.name !== "useQueries") {
|
|
31
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
|
|
32
|
+
context.report({
|
|
33
|
+
node: node.parent,
|
|
34
|
+
messageId: "objectRestDestructure"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
returnValue.elements.forEach((queryResult) => {
|
|
43
|
+
if (queryResult === null) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
|
|
47
|
+
context.report({
|
|
48
|
+
node: queryResult,
|
|
49
|
+
messageId: "objectRestDestructure"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
export {
|
|
58
|
+
name,
|
|
59
|
+
rule
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=no-rest-destructuring.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AAElC,IAAM,OAAO;AAEpB,IAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,IAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,uBAAuB;AAAA,IACzB;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS,GAAG,SAAS;AAC1B,WAAO;AAAA,MACL,eAAe,MAAM;AA1B3B;AA2BQ,YACE,CAAC,SAAS,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAAS,eAAe,oBACrC;AACA;AAAA,QACF;AAEA,cAAM,cAAc,KAAK,OAAO;AAChC,YAAI,KAAK,OAAO,SAAS,cAAc;AACrC,cAAI,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YACb,CAAC;AAAA,UACH;AACA;AAAA,QACF;AAEA,YAAI,YAAY,SAAS,eAAe,cAAc;AACpD;AAAA,QACF;AACA,oBAAY,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACA,cAAI,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YACb,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts
|
|
4
|
+
var import_utils = require("@typescript-eslint/utils");
|
|
5
|
+
var import_test_utils = require("../../utils/test-utils.cjs");
|
|
6
|
+
var import_no_rest_destructuring = require("./no-rest-destructuring.rule.cjs");
|
|
7
|
+
var ruleTester = new import_utils.ESLintUtils.RuleTester({
|
|
8
|
+
parser: "@typescript-eslint/parser",
|
|
9
|
+
settings: {}
|
|
10
|
+
});
|
|
11
|
+
ruleTester.run("no-rest-desctructuring", import_no_rest_destructuring.rule, {
|
|
12
|
+
valid: [
|
|
13
|
+
{
|
|
14
|
+
name: "useQuery is not captured",
|
|
15
|
+
code: import_test_utils.normalizeIndent`
|
|
16
|
+
import { useQuery } from '@tanstack/react-query'
|
|
17
|
+
|
|
18
|
+
function Component() {
|
|
19
|
+
useQuery()
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "useQuery is not destructured",
|
|
26
|
+
code: import_test_utils.normalizeIndent`
|
|
27
|
+
import { useQuery } from '@tanstack/react-query'
|
|
28
|
+
|
|
29
|
+
function Component() {
|
|
30
|
+
const query = useQuery()
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "useQuery is destructured without rest",
|
|
37
|
+
code: import_test_utils.normalizeIndent`
|
|
38
|
+
import { useQuery } from '@tanstack/react-query'
|
|
39
|
+
|
|
40
|
+
function Component() {
|
|
41
|
+
const { data, isLoading, isError } = useQuery()
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "useInfiniteQuery is not captured",
|
|
48
|
+
code: import_test_utils.normalizeIndent`
|
|
49
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
50
|
+
|
|
51
|
+
function Component() {
|
|
52
|
+
useInfiniteQuery()
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
`
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "useInfiniteQuery is not destructured",
|
|
59
|
+
code: import_test_utils.normalizeIndent`
|
|
60
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
61
|
+
|
|
62
|
+
function Component() {
|
|
63
|
+
const query = useInfiniteQuery()
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
`
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "useInfiniteQuery is destructured without rest",
|
|
70
|
+
code: import_test_utils.normalizeIndent`
|
|
71
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
72
|
+
|
|
73
|
+
function Component() {
|
|
74
|
+
const { data, isLoading, isError } = useInfiniteQuery()
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
`
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "useQueries is not captured",
|
|
81
|
+
code: import_test_utils.normalizeIndent`
|
|
82
|
+
import { useQueries } from '@tanstack/react-query'
|
|
83
|
+
|
|
84
|
+
function Component() {
|
|
85
|
+
useQueries([])
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "useQueries is not destructured",
|
|
92
|
+
code: import_test_utils.normalizeIndent`
|
|
93
|
+
import { useQueries } from '@tanstack/react-query'
|
|
94
|
+
|
|
95
|
+
function Component() {
|
|
96
|
+
const queries = useQueries([])
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
`
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "useQueries array has no rest destructured element",
|
|
103
|
+
code: import_test_utils.normalizeIndent`
|
|
104
|
+
import { useQueries } from '@tanstack/react-query'
|
|
105
|
+
|
|
106
|
+
function Component() {
|
|
107
|
+
const [query1, { data, isLoading },, ...others] = useQueries([
|
|
108
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
109
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
110
|
+
{ queryKey: ['key3'], queryFn: () => {} },
|
|
111
|
+
{ queryKey: ['key4'], queryFn: () => {} },
|
|
112
|
+
{ queryKey: ['key5'], queryFn: () => {} },
|
|
113
|
+
])
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
`
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "useQuery is destructured with rest but not from tanstack query",
|
|
120
|
+
code: import_test_utils.normalizeIndent`
|
|
121
|
+
import { useQuery } from 'other-package'
|
|
122
|
+
|
|
123
|
+
function Component() {
|
|
124
|
+
const { data, ...rest } = useQuery()
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
`
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "useInfiniteQuery is destructured with rest but not from tanstack query",
|
|
131
|
+
code: import_test_utils.normalizeIndent`
|
|
132
|
+
import { useInfiniteQuery } from 'other-package'
|
|
133
|
+
|
|
134
|
+
function Component() {
|
|
135
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
`
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "useQueries array has rest destructured element but not from tanstack query",
|
|
142
|
+
code: import_test_utils.normalizeIndent`
|
|
143
|
+
import { useQueries } from 'other-package'
|
|
144
|
+
|
|
145
|
+
function Component() {
|
|
146
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
147
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
148
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
149
|
+
])
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
`
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
invalid: [
|
|
156
|
+
{
|
|
157
|
+
name: "useQuery is destructured with rest",
|
|
158
|
+
code: import_test_utils.normalizeIndent`
|
|
159
|
+
import { useQuery } from '@tanstack/react-query'
|
|
160
|
+
|
|
161
|
+
function Component() {
|
|
162
|
+
const { data, ...rest } = useQuery()
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
`,
|
|
166
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "useInfiniteQuery is destructured with rest",
|
|
170
|
+
code: import_test_utils.normalizeIndent`
|
|
171
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
172
|
+
|
|
173
|
+
function Component() {
|
|
174
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
`,
|
|
178
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: "useQueries array has rest destructured element",
|
|
182
|
+
code: import_test_utils.normalizeIndent`
|
|
183
|
+
import { useQueries } from '@tanstack/react-query'
|
|
184
|
+
|
|
185
|
+
function Component() {
|
|
186
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
187
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
188
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
189
|
+
])
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
`,
|
|
193
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=no-rest-destructuring.test.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { normalizeIndent } from '../../utils/test-utils'\nimport { rule } from './no-rest-destructuring.rule'\n\nconst ruleTester = new ESLintUtils.RuleTester({\n parser: '@typescript-eslint/parser',\n settings: {},\n})\n\nruleTester.run('no-rest-desctructuring', rule, {\n valid: [\n {\n name: 'useQuery is not captured',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n useQuery()\n return\n }\n `,\n },\n {\n name: 'useQuery is not destructured',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const query = useQuery()\n return\n }\n `,\n },\n {\n name: 'useQuery is destructured without rest',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, isLoading, isError } = useQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is not captured',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is not destructured',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const query = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is destructured without rest',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, isLoading, isError } = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useQueries is not captured',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n useQueries([])\n return\n }\n `,\n },\n {\n name: 'useQueries is not destructured',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const queries = useQueries([])\n return\n }\n `,\n },\n {\n name: 'useQueries array has no rest destructured element',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const [query1, { data, isLoading },, ...others] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n { queryKey: ['key3'], queryFn: () => {} },\n { queryKey: ['key4'], queryFn: () => {} },\n { queryKey: ['key5'], queryFn: () => {} },\n ])\n return\n }\n `,\n },\n {\n name: 'useQuery is destructured with rest but not from tanstack query',\n code: normalizeIndent`\n import { useQuery } from 'other-package'\n\n function Component() {\n const { data, ...rest } = useQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is destructured with rest but not from tanstack query',\n code: normalizeIndent`\n import { useInfiniteQuery } from 'other-package'\n\n function Component() {\n const { data, ...rest } = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useQueries array has rest destructured element but not from tanstack query',\n code: normalizeIndent`\n import { useQueries } from 'other-package'\n\n function Component() {\n const [query1, { data, ...rest }] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n ])\n return\n }\n `,\n },\n ],\n invalid: [\n {\n name: 'useQuery is destructured with rest',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, ...rest } = useQuery()\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n {\n name: 'useInfiniteQuery is destructured with rest',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, ...rest } = useInfiniteQuery()\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n {\n name: 'useQueries array has rest destructured element',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const [query1, { data, ...rest }] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n ])\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n ],\n})\n"],"mappings":";;;AAAA,mBAA4B;AAC5B,wBAAgC;AAChC,mCAAqB;AAErB,IAAM,aAAa,IAAI,yBAAY,WAAW;AAAA,EAC5C,QAAQ;AAAA,EACR,UAAU,CAAC;AACb,CAAC;AAED,WAAW,IAAI,0BAA0B,mCAAM;AAAA,EAC7C,OAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWR;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAWN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import { normalizeIndent } from "../../utils/test-utils.js";
|
|
4
|
+
import { rule } from "./no-rest-destructuring.rule.js";
|
|
5
|
+
var ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
settings: {}
|
|
8
|
+
});
|
|
9
|
+
ruleTester.run("no-rest-desctructuring", rule, {
|
|
10
|
+
valid: [
|
|
11
|
+
{
|
|
12
|
+
name: "useQuery is not captured",
|
|
13
|
+
code: normalizeIndent`
|
|
14
|
+
import { useQuery } from '@tanstack/react-query'
|
|
15
|
+
|
|
16
|
+
function Component() {
|
|
17
|
+
useQuery()
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "useQuery is not destructured",
|
|
24
|
+
code: normalizeIndent`
|
|
25
|
+
import { useQuery } from '@tanstack/react-query'
|
|
26
|
+
|
|
27
|
+
function Component() {
|
|
28
|
+
const query = useQuery()
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
`
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "useQuery is destructured without rest",
|
|
35
|
+
code: normalizeIndent`
|
|
36
|
+
import { useQuery } from '@tanstack/react-query'
|
|
37
|
+
|
|
38
|
+
function Component() {
|
|
39
|
+
const { data, isLoading, isError } = useQuery()
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "useInfiniteQuery is not captured",
|
|
46
|
+
code: normalizeIndent`
|
|
47
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
48
|
+
|
|
49
|
+
function Component() {
|
|
50
|
+
useInfiniteQuery()
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
`
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "useInfiniteQuery is not destructured",
|
|
57
|
+
code: normalizeIndent`
|
|
58
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
59
|
+
|
|
60
|
+
function Component() {
|
|
61
|
+
const query = useInfiniteQuery()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
`
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "useInfiniteQuery is destructured without rest",
|
|
68
|
+
code: normalizeIndent`
|
|
69
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
70
|
+
|
|
71
|
+
function Component() {
|
|
72
|
+
const { data, isLoading, isError } = useInfiniteQuery()
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
`
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "useQueries is not captured",
|
|
79
|
+
code: normalizeIndent`
|
|
80
|
+
import { useQueries } from '@tanstack/react-query'
|
|
81
|
+
|
|
82
|
+
function Component() {
|
|
83
|
+
useQueries([])
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
`
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "useQueries is not destructured",
|
|
90
|
+
code: normalizeIndent`
|
|
91
|
+
import { useQueries } from '@tanstack/react-query'
|
|
92
|
+
|
|
93
|
+
function Component() {
|
|
94
|
+
const queries = useQueries([])
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
`
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "useQueries array has no rest destructured element",
|
|
101
|
+
code: normalizeIndent`
|
|
102
|
+
import { useQueries } from '@tanstack/react-query'
|
|
103
|
+
|
|
104
|
+
function Component() {
|
|
105
|
+
const [query1, { data, isLoading },, ...others] = useQueries([
|
|
106
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
107
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
108
|
+
{ queryKey: ['key3'], queryFn: () => {} },
|
|
109
|
+
{ queryKey: ['key4'], queryFn: () => {} },
|
|
110
|
+
{ queryKey: ['key5'], queryFn: () => {} },
|
|
111
|
+
])
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
`
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "useQuery is destructured with rest but not from tanstack query",
|
|
118
|
+
code: normalizeIndent`
|
|
119
|
+
import { useQuery } from 'other-package'
|
|
120
|
+
|
|
121
|
+
function Component() {
|
|
122
|
+
const { data, ...rest } = useQuery()
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
`
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "useInfiniteQuery is destructured with rest but not from tanstack query",
|
|
129
|
+
code: normalizeIndent`
|
|
130
|
+
import { useInfiniteQuery } from 'other-package'
|
|
131
|
+
|
|
132
|
+
function Component() {
|
|
133
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
`
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "useQueries array has rest destructured element but not from tanstack query",
|
|
140
|
+
code: normalizeIndent`
|
|
141
|
+
import { useQueries } from 'other-package'
|
|
142
|
+
|
|
143
|
+
function Component() {
|
|
144
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
145
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
146
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
147
|
+
])
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
`
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
invalid: [
|
|
154
|
+
{
|
|
155
|
+
name: "useQuery is destructured with rest",
|
|
156
|
+
code: normalizeIndent`
|
|
157
|
+
import { useQuery } from '@tanstack/react-query'
|
|
158
|
+
|
|
159
|
+
function Component() {
|
|
160
|
+
const { data, ...rest } = useQuery()
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
`,
|
|
164
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "useInfiniteQuery is destructured with rest",
|
|
168
|
+
code: normalizeIndent`
|
|
169
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
170
|
+
|
|
171
|
+
function Component() {
|
|
172
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
`,
|
|
176
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: "useQueries array has rest destructured element",
|
|
180
|
+
code: normalizeIndent`
|
|
181
|
+
import { useQueries } from '@tanstack/react-query'
|
|
182
|
+
|
|
183
|
+
function Component() {
|
|
184
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
185
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
186
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
187
|
+
])
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
`,
|
|
191
|
+
errors: [{ messageId: "objectRestDestructure" }]
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=no-rest-destructuring.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.test.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { normalizeIndent } from '../../utils/test-utils'\nimport { rule } from './no-rest-destructuring.rule'\n\nconst ruleTester = new ESLintUtils.RuleTester({\n parser: '@typescript-eslint/parser',\n settings: {},\n})\n\nruleTester.run('no-rest-desctructuring', rule, {\n valid: [\n {\n name: 'useQuery is not captured',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n useQuery()\n return\n }\n `,\n },\n {\n name: 'useQuery is not destructured',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const query = useQuery()\n return\n }\n `,\n },\n {\n name: 'useQuery is destructured without rest',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, isLoading, isError } = useQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is not captured',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is not destructured',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const query = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is destructured without rest',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, isLoading, isError } = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useQueries is not captured',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n useQueries([])\n return\n }\n `,\n },\n {\n name: 'useQueries is not destructured',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const queries = useQueries([])\n return\n }\n `,\n },\n {\n name: 'useQueries array has no rest destructured element',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const [query1, { data, isLoading },, ...others] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n { queryKey: ['key3'], queryFn: () => {} },\n { queryKey: ['key4'], queryFn: () => {} },\n { queryKey: ['key5'], queryFn: () => {} },\n ])\n return\n }\n `,\n },\n {\n name: 'useQuery is destructured with rest but not from tanstack query',\n code: normalizeIndent`\n import { useQuery } from 'other-package'\n\n function Component() {\n const { data, ...rest } = useQuery()\n return\n }\n `,\n },\n {\n name: 'useInfiniteQuery is destructured with rest but not from tanstack query',\n code: normalizeIndent`\n import { useInfiniteQuery } from 'other-package'\n\n function Component() {\n const { data, ...rest } = useInfiniteQuery()\n return\n }\n `,\n },\n {\n name: 'useQueries array has rest destructured element but not from tanstack query',\n code: normalizeIndent`\n import { useQueries } from 'other-package'\n\n function Component() {\n const [query1, { data, ...rest }] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n ])\n return\n }\n `,\n },\n ],\n invalid: [\n {\n name: 'useQuery is destructured with rest',\n code: normalizeIndent`\n import { useQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, ...rest } = useQuery()\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n {\n name: 'useInfiniteQuery is destructured with rest',\n code: normalizeIndent`\n import { useInfiniteQuery } from '@tanstack/react-query'\n\n function Component() {\n const { data, ...rest } = useInfiniteQuery()\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n {\n name: 'useQueries array has rest destructured element',\n code: normalizeIndent`\n import { useQueries } from '@tanstack/react-query'\n\n function Component() {\n const [query1, { data, ...rest }] = useQueries([\n { queryKey: ['key1'], queryFn: () => {} },\n { queryKey: ['key2'], queryFn: () => {} },\n ])\n return\n }\n `,\n errors: [{ messageId: 'objectRestDestructure' }],\n },\n ],\n})\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,YAAY;AAErB,IAAM,aAAa,IAAI,YAAY,WAAW;AAAA,EAC5C,QAAQ;AAAA,EACR,UAAU,CAAC;AACb,CAAC;AAED,WAAW,IAAI,0BAA0B,MAAM;AAAA,EAC7C,OAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAcR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQR;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWR;AAAA,EACF;AAAA,EACA,SAAS;AAAA,IACP;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAQN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAWN,QAAQ,CAAC,EAAE,WAAW,wBAAwB,CAAC;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts
|
|
21
|
+
var no_rest_destructuring_utils_exports = {};
|
|
22
|
+
__export(no_rest_destructuring_utils_exports, {
|
|
23
|
+
NoRestDestructuringUtils: () => NoRestDestructuringUtils
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(no_rest_destructuring_utils_exports);
|
|
26
|
+
var import_utils = require("@typescript-eslint/utils");
|
|
27
|
+
var NoRestDestructuringUtils = {
|
|
28
|
+
isObjectRestDestructuring(node) {
|
|
29
|
+
if (node.type !== import_utils.AST_NODE_TYPES.ObjectPattern) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return node.properties.some((p) => p.type === import_utils.AST_NODE_TYPES.RestElement);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
NoRestDestructuringUtils
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=no-rest-destructuring.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAGxB,IAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AACtD,QAAI,KAAK,SAAS,4BAAe,eAAe;AAC9C,aAAO;AAAA,IACT;AACA,WAAO,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,4BAAe,WAAW;AAAA,EAC1E;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts
|
|
2
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
3
|
+
var NoRestDestructuringUtils = {
|
|
4
|
+
isObjectRestDestructuring(node) {
|
|
5
|
+
if (node.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
NoRestDestructuringUtils
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=no-rest-destructuring.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAGxB,IAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AACtD,QAAI,KAAK,SAAS,eAAe,eAAe;AAC9C,aAAO;AAAA,IACT;AACA,WAAO,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,eAAe,WAAW;AAAA,EAC1E;AACF;","names":[]}
|
package/build/legacy/rules.cjs
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name4 in all)
|
|
10
|
+
__defProp(target, name4, { get: all[name4], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -35,9 +35,11 @@ __export(rules_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(rules_exports);
|
|
36
36
|
var exhaustiveDeps = __toESM(require("./rules/exhaustive-deps.rule.cjs"), 1);
|
|
37
37
|
var stableQueryClient = __toESM(require("./rules/stable-query-client/stable-query-client.rule.cjs"), 1);
|
|
38
|
+
var noRestDestructuring = __toESM(require("./rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs"), 1);
|
|
38
39
|
var rules = {
|
|
39
40
|
[exhaustiveDeps.name]: exhaustiveDeps.rule,
|
|
40
|
-
[stableQueryClient.name]: stableQueryClient.rule
|
|
41
|
+
[stableQueryClient.name]: stableQueryClient.rule,
|
|
42
|
+
[noRestDestructuring.name]: noRestDestructuring.rule
|
|
41
43
|
};
|
|
42
44
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
45
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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'\n\nexport const rules = {\n [exhaustiveDeps.name]: exhaustiveDeps.rule,\n [stableQueryClient.name]: stableQueryClient.rule,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAChC,wBAAmC;
|
|
1
|
+
{"version":3,"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAgC;AAChC,wBAAmC;AACnC,0BAAqC;AAE9B,IAAM,QAAQ;AAAA,EACnB,CAAgB,mBAAI,GAAkB;AAAA,EACtC,CAAmB,sBAAI,GAAqB;AAAA,EAC5C,CAAqB,wBAAI,GAAuB;AAClD;","names":[]}
|
package/build/legacy/rules.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslin
|
|
|
3
3
|
declare const rules: {
|
|
4
4
|
"exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
5
5
|
"stable-query-client": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
|
+
"no-rest-destructuring": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export { rules };
|
package/build/legacy/rules.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslin
|
|
|
3
3
|
declare const rules: {
|
|
4
4
|
"exhaustive-deps": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
5
5
|
"stable-query-client": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
|
+
"no-rest-destructuring": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<string, readonly unknown[], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
export { rules };
|
package/build/legacy/rules.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// src/rules.ts
|
|
2
2
|
import * as exhaustiveDeps from "./rules/exhaustive-deps.rule.js";
|
|
3
3
|
import * as stableQueryClient from "./rules/stable-query-client/stable-query-client.rule.js";
|
|
4
|
+
import * as noRestDestructuring from "./rules/no-rest-desctructuring/no-rest-destructuring.rule.js";
|
|
4
5
|
var rules = {
|
|
5
6
|
[exhaustiveDeps.name]: exhaustiveDeps.rule,
|
|
6
|
-
[stableQueryClient.name]: stableQueryClient.rule
|
|
7
|
+
[stableQueryClient.name]: stableQueryClient.rule,
|
|
8
|
+
[noRestDestructuring.name]: noRestDestructuring.rule
|
|
7
9
|
};
|
|
8
10
|
export {
|
|
9
11
|
rules
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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'\n\nexport const rules = {\n [exhaustiveDeps.name]: exhaustiveDeps.rule,\n [stableQueryClient.name]: stableQueryClient.rule,\n}\n"],"mappings":";AAAA,YAAY,oBAAoB;AAChC,YAAY,uBAAuB;
|
|
1
|
+
{"version":3,"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"],"mappings":";AAAA,YAAY,oBAAoB;AAChC,YAAY,uBAAuB;AACnC,YAAY,yBAAyB;AAE9B,IAAM,QAAQ;AAAA,EACnB,CAAgB,mBAAI,GAAkB;AAAA,EACtC,CAAmB,sBAAI,GAAqB;AAAA,EAC5C,CAAqB,wBAAI,GAAuB;AAClD;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
1
2
|
import { configs } from '../configs'
|
|
2
3
|
|
|
3
4
|
describe('configs', () => {
|
|
@@ -10,6 +11,7 @@ describe('configs', () => {
|
|
|
10
11
|
],
|
|
11
12
|
"rules": {
|
|
12
13
|
"@tanstack/query/exhaustive-deps": "error",
|
|
14
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
13
15
|
"@tanstack/query/stable-query-client": "error",
|
|
14
16
|
},
|
|
15
17
|
},
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import { createRule } from '../../utils/create-rule'
|
|
3
|
+
import { ASTUtils } from '../../utils/ast-utils'
|
|
4
|
+
import { NoRestDestructuringUtils } from './no-rest-destructuring.utils'
|
|
5
|
+
|
|
6
|
+
export const name = 'no-rest-destructuring'
|
|
7
|
+
|
|
8
|
+
const queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']
|
|
9
|
+
|
|
10
|
+
export const rule = createRule({
|
|
11
|
+
name,
|
|
12
|
+
meta: {
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Disallows rest destructuring in queries',
|
|
16
|
+
recommended: 'warn',
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`,
|
|
20
|
+
},
|
|
21
|
+
schema: [],
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [],
|
|
24
|
+
|
|
25
|
+
create(context, _, helpers) {
|
|
26
|
+
return {
|
|
27
|
+
CallExpression(node) {
|
|
28
|
+
if (
|
|
29
|
+
!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||
|
|
30
|
+
!helpers.isTanstackQueryImport(node.callee) ||
|
|
31
|
+
node.parent?.type !== AST_NODE_TYPES.VariableDeclarator
|
|
32
|
+
) {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const returnValue = node.parent.id
|
|
37
|
+
if (node.callee.name !== 'useQueries') {
|
|
38
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {
|
|
39
|
+
context.report({
|
|
40
|
+
node: node.parent,
|
|
41
|
+
messageId: 'objectRestDestructure',
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
returnValue.elements.forEach((queryResult) => {
|
|
51
|
+
if (queryResult === null) {
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {
|
|
55
|
+
context.report({
|
|
56
|
+
node: queryResult,
|
|
57
|
+
messageId: 'objectRestDestructure',
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
})
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils'
|
|
2
|
+
import { normalizeIndent } from '../../utils/test-utils'
|
|
3
|
+
import { rule } from './no-rest-destructuring.rule'
|
|
4
|
+
|
|
5
|
+
const ruleTester = new ESLintUtils.RuleTester({
|
|
6
|
+
parser: '@typescript-eslint/parser',
|
|
7
|
+
settings: {},
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
ruleTester.run('no-rest-desctructuring', rule, {
|
|
11
|
+
valid: [
|
|
12
|
+
{
|
|
13
|
+
name: 'useQuery is not captured',
|
|
14
|
+
code: normalizeIndent`
|
|
15
|
+
import { useQuery } from '@tanstack/react-query'
|
|
16
|
+
|
|
17
|
+
function Component() {
|
|
18
|
+
useQuery()
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'useQuery is not destructured',
|
|
25
|
+
code: normalizeIndent`
|
|
26
|
+
import { useQuery } from '@tanstack/react-query'
|
|
27
|
+
|
|
28
|
+
function Component() {
|
|
29
|
+
const query = useQuery()
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'useQuery is destructured without rest',
|
|
36
|
+
code: normalizeIndent`
|
|
37
|
+
import { useQuery } from '@tanstack/react-query'
|
|
38
|
+
|
|
39
|
+
function Component() {
|
|
40
|
+
const { data, isLoading, isError } = useQuery()
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
`,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'useInfiniteQuery is not captured',
|
|
47
|
+
code: normalizeIndent`
|
|
48
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
49
|
+
|
|
50
|
+
function Component() {
|
|
51
|
+
useInfiniteQuery()
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'useInfiniteQuery is not destructured',
|
|
58
|
+
code: normalizeIndent`
|
|
59
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
60
|
+
|
|
61
|
+
function Component() {
|
|
62
|
+
const query = useInfiniteQuery()
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
`,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'useInfiniteQuery is destructured without rest',
|
|
69
|
+
code: normalizeIndent`
|
|
70
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
71
|
+
|
|
72
|
+
function Component() {
|
|
73
|
+
const { data, isLoading, isError } = useInfiniteQuery()
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
`,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'useQueries is not captured',
|
|
80
|
+
code: normalizeIndent`
|
|
81
|
+
import { useQueries } from '@tanstack/react-query'
|
|
82
|
+
|
|
83
|
+
function Component() {
|
|
84
|
+
useQueries([])
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
`,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'useQueries is not destructured',
|
|
91
|
+
code: normalizeIndent`
|
|
92
|
+
import { useQueries } from '@tanstack/react-query'
|
|
93
|
+
|
|
94
|
+
function Component() {
|
|
95
|
+
const queries = useQueries([])
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'useQueries array has no rest destructured element',
|
|
102
|
+
code: normalizeIndent`
|
|
103
|
+
import { useQueries } from '@tanstack/react-query'
|
|
104
|
+
|
|
105
|
+
function Component() {
|
|
106
|
+
const [query1, { data, isLoading },, ...others] = useQueries([
|
|
107
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
108
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
109
|
+
{ queryKey: ['key3'], queryFn: () => {} },
|
|
110
|
+
{ queryKey: ['key4'], queryFn: () => {} },
|
|
111
|
+
{ queryKey: ['key5'], queryFn: () => {} },
|
|
112
|
+
])
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'useQuery is destructured with rest but not from tanstack query',
|
|
119
|
+
code: normalizeIndent`
|
|
120
|
+
import { useQuery } from 'other-package'
|
|
121
|
+
|
|
122
|
+
function Component() {
|
|
123
|
+
const { data, ...rest } = useQuery()
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
`,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'useInfiniteQuery is destructured with rest but not from tanstack query',
|
|
130
|
+
code: normalizeIndent`
|
|
131
|
+
import { useInfiniteQuery } from 'other-package'
|
|
132
|
+
|
|
133
|
+
function Component() {
|
|
134
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'useQueries array has rest destructured element but not from tanstack query',
|
|
141
|
+
code: normalizeIndent`
|
|
142
|
+
import { useQueries } from 'other-package'
|
|
143
|
+
|
|
144
|
+
function Component() {
|
|
145
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
146
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
147
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
148
|
+
])
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
`,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
invalid: [
|
|
155
|
+
{
|
|
156
|
+
name: 'useQuery is destructured with rest',
|
|
157
|
+
code: normalizeIndent`
|
|
158
|
+
import { useQuery } from '@tanstack/react-query'
|
|
159
|
+
|
|
160
|
+
function Component() {
|
|
161
|
+
const { data, ...rest } = useQuery()
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
`,
|
|
165
|
+
errors: [{ messageId: 'objectRestDestructure' }],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'useInfiniteQuery is destructured with rest',
|
|
169
|
+
code: normalizeIndent`
|
|
170
|
+
import { useInfiniteQuery } from '@tanstack/react-query'
|
|
171
|
+
|
|
172
|
+
function Component() {
|
|
173
|
+
const { data, ...rest } = useInfiniteQuery()
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
`,
|
|
177
|
+
errors: [{ messageId: 'objectRestDestructure' }],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'useQueries array has rest destructured element',
|
|
181
|
+
code: normalizeIndent`
|
|
182
|
+
import { useQueries } from '@tanstack/react-query'
|
|
183
|
+
|
|
184
|
+
function Component() {
|
|
185
|
+
const [query1, { data, ...rest }] = useQueries([
|
|
186
|
+
{ queryKey: ['key1'], queryFn: () => {} },
|
|
187
|
+
{ queryKey: ['key2'], queryFn: () => {} },
|
|
188
|
+
])
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
`,
|
|
192
|
+
errors: [{ messageId: 'objectRestDestructure' }],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
import type { TSESTree } from '@typescript-eslint/utils'
|
|
3
|
+
|
|
4
|
+
export const NoRestDestructuringUtils = {
|
|
5
|
+
isObjectRestDestructuring(node: TSESTree.Node): boolean {
|
|
6
|
+
if (node.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)
|
|
10
|
+
},
|
|
11
|
+
}
|
package/src/rules.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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
|
+
import * as noRestDestructuring from './rules/no-rest-desctructuring/no-rest-destructuring.rule'
|
|
3
4
|
|
|
4
5
|
export const rules = {
|
|
5
6
|
[exhaustiveDeps.name]: exhaustiveDeps.rule,
|
|
6
7
|
[stableQueryClient.name]: stableQueryClient.rule,
|
|
8
|
+
[noRestDestructuring.name]: noRestDestructuring.rule,
|
|
7
9
|
}
|