@tanstack/eslint-plugin-query 5.20.0 → 5.20.1
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/dist/cjs/configs.cjs.map +1 -1
- package/dist/cjs/configs.d.cts +2 -2
- package/dist/cjs/rules/{exhaustive-deps.rule.cjs → exhaustive-deps/exhaustive-deps.rule.cjs} +8 -6
- package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.rule.cjs.map +1 -0
- package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.rule.d.cts +3 -0
- package/dist/cjs/rules/{exhaustive-deps.utils.cjs → exhaustive-deps/exhaustive-deps.utils.cjs} +1 -1
- package/dist/cjs/rules/exhaustive-deps/exhaustive-deps.utils.cjs.map +1 -0
- package/dist/cjs/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.rule.cjs +6 -4
- package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.rule.cjs.map +1 -0
- package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.rule.d.cts +3 -0
- package/dist/cjs/rules/no-rest-destructuring/no-rest-destructuring.utils.cjs.map +1 -0
- package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs +6 -4
- package/dist/cjs/rules/stable-query-client/stable-query-client.rule.cjs.map +1 -1
- package/dist/cjs/rules/stable-query-client/stable-query-client.rule.d.cts +2 -2
- package/dist/cjs/rules.cjs +2 -2
- package/dist/cjs/rules.cjs.map +1 -1
- package/dist/cjs/rules.d.cts +1 -1
- package/dist/cjs/utils/detect-react-query-imports.cjs.map +1 -1
- package/dist/cjs/utils/detect-react-query-imports.d.cts +1 -1
- package/dist/cjs/utils/get-docs-url.cjs +5 -0
- package/dist/cjs/utils/get-docs-url.cjs.map +1 -0
- package/dist/cjs/utils/get-docs-url.d.cts +1 -0
- package/dist/esm/configs.d.ts +2 -2
- package/dist/esm/configs.js.map +1 -1
- package/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.d.ts +3 -0
- package/dist/esm/rules/{exhaustive-deps.rule.js → exhaustive-deps/exhaustive-deps.rule.js} +8 -6
- package/dist/esm/rules/exhaustive-deps/exhaustive-deps.rule.js.map +1 -0
- package/dist/esm/rules/{exhaustive-deps.utils.js → exhaustive-deps/exhaustive-deps.utils.js} +1 -1
- package/dist/esm/rules/exhaustive-deps/exhaustive-deps.utils.js.map +1 -0
- package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.d.ts +3 -0
- package/dist/esm/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.rule.js +6 -4
- package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.rule.js.map +1 -0
- package/dist/esm/rules/no-rest-destructuring/no-rest-destructuring.utils.js.map +1 -0
- package/dist/esm/rules/stable-query-client/stable-query-client.rule.d.ts +2 -2
- package/dist/esm/rules/stable-query-client/stable-query-client.rule.js +6 -4
- package/dist/esm/rules/stable-query-client/stable-query-client.rule.js.map +1 -1
- package/dist/esm/rules.d.ts +1 -1
- package/dist/esm/rules.js +2 -2
- package/dist/esm/rules.js.map +1 -1
- package/dist/esm/utils/detect-react-query-imports.d.ts +1 -1
- package/dist/esm/utils/detect-react-query-imports.js.map +1 -1
- package/dist/esm/utils/get-docs-url.d.ts +1 -0
- package/dist/esm/utils/get-docs-url.js +5 -0
- package/dist/esm/utils/get-docs-url.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/exhaustive-deps.test.ts +2 -5
- package/src/{rules/no-rest-desctructuring → __tests__}/no-rest-destructuring.test.ts +2 -2
- package/src/{rules/stable-query-client → __tests__}/stable-query-client.test.ts +2 -2
- package/src/configs.ts +9 -2
- package/src/rules/{exhaustive-deps.rule.ts → exhaustive-deps/exhaustive-deps.rule.ts} +11 -12
- package/src/rules/{exhaustive-deps.utils.ts → exhaustive-deps/exhaustive-deps.utils.ts} +1 -1
- package/src/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.rule.ts +8 -10
- package/src/rules/stable-query-client/stable-query-client.rule.ts +8 -10
- package/src/rules.ts +7 -3
- package/src/utils/detect-react-query-imports.ts +1 -1
- package/src/utils/get-docs-url.ts +2 -0
- package/dist/cjs/rules/exhaustive-deps.rule.cjs.map +0 -1
- package/dist/cjs/rules/exhaustive-deps.rule.d.cts +0 -3
- package/dist/cjs/rules/exhaustive-deps.utils.cjs.map +0 -1
- package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.cjs.map +0 -1
- package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.cts +0 -3
- package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.test.d.cts +0 -1
- package/dist/cjs/rules/no-rest-desctructuring/no-rest-destructuring.utils.cjs.map +0 -1
- package/dist/cjs/rules/stable-query-client/stable-query-client.test.d.cts +0 -1
- package/dist/cjs/utils/create-rule.cjs +0 -13
- package/dist/cjs/utils/create-rule.cjs.map +0 -1
- package/dist/cjs/utils/create-rule.d.cts +0 -7
- package/dist/cjs/utils/test-utils.d.cts +0 -1
- package/dist/esm/rules/exhaustive-deps.rule.d.ts +0 -3
- package/dist/esm/rules/exhaustive-deps.rule.js.map +0 -1
- package/dist/esm/rules/exhaustive-deps.utils.js.map +0 -1
- package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.d.ts +0 -3
- package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.rule.js.map +0 -1
- package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.test.d.ts +0 -1
- package/dist/esm/rules/no-rest-desctructuring/no-rest-destructuring.utils.js.map +0 -1
- package/dist/esm/rules/stable-query-client/stable-query-client.test.d.ts +0 -1
- package/dist/esm/utils/create-rule.d.ts +0 -7
- package/dist/esm/utils/create-rule.js +0 -13
- package/dist/esm/utils/create-rule.js.map +0 -1
- package/dist/esm/utils/test-utils.d.ts +0 -1
- package/src/utils/create-rule.ts +0 -20
- /package/dist/cjs/rules/{exhaustive-deps.utils.d.cts → exhaustive-deps/exhaustive-deps.utils.d.cts} +0 -0
- /package/dist/cjs/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.cjs +0 -0
- /package/dist/cjs/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.d.cts +0 -0
- /package/dist/esm/rules/{exhaustive-deps.utils.d.ts → exhaustive-deps/exhaustive-deps.utils.d.ts} +0 -0
- /package/dist/esm/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.d.ts +0 -0
- /package/dist/esm/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.js +0 -0
- /package/src/{utils → __tests__}/test-utils.ts +0 -0
- /package/src/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.ts +0 -0
package/dist/cjs/configs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.cjs","sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type {
|
|
1
|
+
{"version":3,"file":"configs.cjs","sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ESLintUtils.RuleListener\n >\n >,\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,UAQA;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;;"}
|
package/dist/cjs/configs.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
export declare const configs: {
|
|
3
3
|
recommended: {
|
|
4
4
|
plugins: string[];
|
|
5
|
-
rules: [string,
|
|
5
|
+
rules: [string, ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>];
|
|
6
6
|
};
|
|
7
7
|
};
|
package/dist/cjs/rules/{exhaustive-deps.rule.cjs → exhaustive-deps/exhaustive-deps.rule.cjs}
RENAMED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const utils = require("@typescript-eslint/utils");
|
|
4
|
-
const astUtils = require("
|
|
5
|
-
const
|
|
6
|
-
const uniqueBy = require("
|
|
4
|
+
const astUtils = require("../../utils/ast-utils.cjs");
|
|
5
|
+
const getDocsUrl = require("../../utils/get-docs-url.cjs");
|
|
6
|
+
const uniqueBy = require("../../utils/unique-by.cjs");
|
|
7
|
+
const detectReactQueryImports = require("../../utils/detect-react-query-imports.cjs");
|
|
7
8
|
const exhaustiveDeps_utils = require("./exhaustive-deps.utils.cjs");
|
|
8
9
|
const QUERY_KEY = "queryKey";
|
|
9
10
|
const QUERY_FN = "queryFn";
|
|
10
11
|
const name = "exhaustive-deps";
|
|
11
|
-
const
|
|
12
|
+
const createRule = utils.ESLintUtils.RuleCreator(getDocsUrl.getDocsUrl);
|
|
13
|
+
const rule = createRule({
|
|
12
14
|
name,
|
|
13
15
|
meta: {
|
|
14
16
|
type: "problem",
|
|
@@ -25,7 +27,7 @@ const rule = createRule.createRule({
|
|
|
25
27
|
schema: []
|
|
26
28
|
},
|
|
27
29
|
defaultOptions: [],
|
|
28
|
-
create: (context) => {
|
|
30
|
+
create: detectReactQueryImports.detectTanstackQueryImports((context) => {
|
|
29
31
|
return {
|
|
30
32
|
Property: (node) => {
|
|
31
33
|
if (!astUtils.ASTUtils.isObjectExpression(node.parent) || !astUtils.ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
|
|
@@ -107,7 +109,7 @@ const rule = createRule.createRule({
|
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
|
-
}
|
|
112
|
+
})
|
|
111
113
|
});
|
|
112
114
|
exports.name = name;
|
|
113
115
|
exports.rule = rule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustive-deps.rule.cjs","sources":["../../../../src/rules/exhaustive-deps/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { uniqueBy } from '../../utils/unique-by'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\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\nconst createRule = ESLintUtils.RuleCreator(getDocsUrl)\n\nexport const rule = 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: detectTanstackQueryImports((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":["ESLintUtils","getDocsUrl","detectTanstackQueryImports","ASTUtils","AST_NODE_TYPES","ExhaustiveDepsUtils","uniqueBy"],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;AAEV,MAAM,OAAO;AAEpB,MAAM,aAAaA,MAAY,YAAA,YAAYC,WAAAA,UAAU;AAE9C,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,QAAQC,wBAAAA,2BAA2B,CAAC,YAAY;AACvC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js/rules/{exhaustive-deps.utils.cjs → exhaustive-deps/exhaustive-deps.utils.cjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const utils = require("@typescript-eslint/utils");
|
|
4
|
-
const astUtils = require("
|
|
4
|
+
const astUtils = require("../../utils/ast-utils.cjs");
|
|
5
5
|
const ExhaustiveDepsUtils = {
|
|
6
6
|
isRelevantReference(params) {
|
|
7
7
|
const { reference, scopeManager, context } = params;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustive-deps.utils.cjs","sources":["../../../../src/rules/exhaustive-deps/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;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const utils = require("@typescript-eslint/utils");
|
|
4
|
-
const
|
|
4
|
+
const getDocsUrl = require("../../utils/get-docs-url.cjs");
|
|
5
5
|
const astUtils = require("../../utils/ast-utils.cjs");
|
|
6
|
+
const detectReactQueryImports = require("../../utils/detect-react-query-imports.cjs");
|
|
6
7
|
const noRestDestructuring_utils = require("./no-rest-destructuring.utils.cjs");
|
|
7
8
|
const name = "no-rest-destructuring";
|
|
8
9
|
const queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
|
|
9
|
-
const
|
|
10
|
+
const createRule = utils.ESLintUtils.RuleCreator(getDocsUrl.getDocsUrl);
|
|
11
|
+
const rule = createRule({
|
|
10
12
|
name,
|
|
11
13
|
meta: {
|
|
12
14
|
type: "problem",
|
|
@@ -20,7 +22,7 @@ const rule = createRule.createRule({
|
|
|
20
22
|
schema: []
|
|
21
23
|
},
|
|
22
24
|
defaultOptions: [],
|
|
23
|
-
create: (context, _, helpers) => {
|
|
25
|
+
create: detectReactQueryImports.detectTanstackQueryImports((context, _, helpers) => {
|
|
24
26
|
return {
|
|
25
27
|
CallExpression: (node) => {
|
|
26
28
|
if (!astUtils.ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator) {
|
|
@@ -52,7 +54,7 @@ const rule = createRule.createRule({
|
|
|
52
54
|
});
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
|
-
}
|
|
57
|
+
})
|
|
56
58
|
});
|
|
57
59
|
exports.name = name;
|
|
58
60
|
exports.rule = rule;
|
|
@@ -0,0 +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'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nconst createRule = ESLintUtils.RuleCreator(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' 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: 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 (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":["ESLintUtils","getDocsUrl","detectTanstackQueryImports","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;;AAMO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEhE,MAAM,aAAaA,MAAY,YAAA,YAAYC,WAAAA,UAAU;AAE9C,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,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,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,EACF,CACD;AACH,CAAC;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-rest-destructuring.utils.cjs","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"names":["AST_NODE_TYPES"],"mappings":";;;AAGO,MAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AAClD,QAAA,KAAK,SAASA,MAAA,eAAe,eAAe;AACvC,aAAA;AAAA,IACT;AACO,WAAA,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAASA,qBAAe,WAAW;AAAA,EAC1E;AACF;;"}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const utils = require("@typescript-eslint/utils");
|
|
4
4
|
const astUtils = require("../../utils/ast-utils.cjs");
|
|
5
|
-
const
|
|
5
|
+
const getDocsUrl = require("../../utils/get-docs-url.cjs");
|
|
6
|
+
const detectReactQueryImports = require("../../utils/detect-react-query-imports.cjs");
|
|
6
7
|
const name = "stable-query-client";
|
|
7
|
-
const
|
|
8
|
+
const createRule = utils.ESLintUtils.RuleCreator(getDocsUrl.getDocsUrl);
|
|
9
|
+
const rule = createRule({
|
|
8
10
|
name,
|
|
9
11
|
meta: {
|
|
10
12
|
type: "problem",
|
|
@@ -24,7 +26,7 @@ const rule = createRule.createRule({
|
|
|
24
26
|
schema: []
|
|
25
27
|
},
|
|
26
28
|
defaultOptions: [],
|
|
27
|
-
create: (context, _, helpers) => {
|
|
29
|
+
create: detectReactQueryImports.detectTanstackQueryImports((context, _, helpers) => {
|
|
28
30
|
return {
|
|
29
31
|
NewExpression: (node) => {
|
|
30
32
|
if (node.callee.type !== utils.AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== utils.AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
|
|
@@ -58,7 +60,7 @@ const rule = createRule.createRule({
|
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
};
|
|
61
|
-
}
|
|
63
|
+
})
|
|
62
64
|
});
|
|
63
65
|
exports.name = name;
|
|
64
66
|
exports.rule = rule;
|
|
@@ -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 {
|
|
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, ESLintUtils } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const name = 'stable-query-client'\n\nconst createRule = ESLintUtils.RuleCreator(getDocsUrl)\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' 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: detectTanstackQueryImports((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":["ESLintUtils","getDocsUrl","detectTanstackQueryImports","AST_NODE_TYPES","ASTUtils"],"mappings":";;;;;;AAMO,MAAM,OAAO;AAEpB,MAAM,aAAaA,MAAY,YAAA,YAAYC,WAAAA,UAAU;AAE9C,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA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AAAA,IAAA;AAAA,EACF,CACD;AACH,CAAC;;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
export declare const name = "stable-query-client";
|
|
3
|
-
export declare const rule: ESLintUtils.RuleModule<string,
|
|
3
|
+
export declare const rule: ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
|
package/dist/cjs/rules.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const exhaustiveDeps_rule = require("./rules/exhaustive-deps.rule.cjs");
|
|
3
|
+
const exhaustiveDeps_rule = require("./rules/exhaustive-deps/exhaustive-deps.rule.cjs");
|
|
4
4
|
const stableQueryClient_rule = require("./rules/stable-query-client/stable-query-client.rule.cjs");
|
|
5
|
-
const noRestDestructuring_rule = require("./rules/no-rest-
|
|
5
|
+
const noRestDestructuring_rule = require("./rules/no-rest-destructuring/no-rest-destructuring.rule.cjs");
|
|
6
6
|
const rules = {
|
|
7
7
|
[exhaustiveDeps_rule.name]: exhaustiveDeps_rule.rule,
|
|
8
8
|
[stableQueryClient_rule.name]: stableQueryClient_rule.rule,
|
package/dist/cjs/rules.cjs.map
CHANGED
|
@@ -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-
|
|
1
|
+
{"version":3,"file":"rules.cjs","sources":["../../src/rules.ts"],"sourcesContent":["import * as exhaustiveDeps from './rules/exhaustive-deps/exhaustive-deps.rule'\nimport * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'\nimport * as noRestDestructuring from './rules/no-rest-destructuring/no-rest-destructuring.rule'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ESLintUtils.RuleListener\n >\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,QAOT;AAAA,EACF,CAACA,oBAAmB,IAAA,GAAGC,oBAAe;AAAA,EACtC,CAACC,uBAAsB,IAAA,GAAGC,uBAAkB;AAAA,EAC5C,CAACC,yBAAwB,IAAA,GAAGC,yBAAoB;AAClD;;"}
|
package/dist/cjs/rules.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const rules: Record<string, ESLintUtils.RuleModule<string,
|
|
2
|
+
export declare const rules: Record<string, ESLintUtils.RuleModule<string, ReadonlyArray<unknown>, ESLintUtils.RuleListener>>;
|
|
@@ -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\
|
|
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\ntype 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,mBAC3C,UAAU,OAAO,SACfA,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;;"}
|
|
@@ -7,6 +7,6 @@ type Helpers = {
|
|
|
7
7
|
isSpecificTanstackQueryImport: (node: TSESTree.Identifier, source: string) => boolean;
|
|
8
8
|
isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
|
|
11
11
|
export declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
|
|
12
12
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-docs-url.cjs","sources":["../../../src/utils/get-docs-url.ts"],"sourcesContent":["export const getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/latest/docs/eslint/${ruleName}`\n"],"names":[],"mappings":";;AAAO,MAAM,aAAa,CAAC,aACzB,iDAAiD,QAAQ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDocsUrl: (ruleName: string) => string;
|
package/dist/esm/configs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
export declare const configs: {
|
|
3
3
|
recommended: {
|
|
4
4
|
plugins: string[];
|
|
5
|
-
rules: [string,
|
|
5
|
+
rules: [string, ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>];
|
|
6
6
|
};
|
|
7
7
|
};
|
package/dist/esm/configs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.js","sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type {
|
|
1
|
+
{"version":3,"file":"configs.js","sources":["../../src/configs.ts"],"sourcesContent":["import { rules } from './rules'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nfunction generateRecommendedConfig(\n allRules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ESLintUtils.RuleListener\n >\n >,\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,UAQA;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,11 +1,13 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
-
import { ASTUtils } from "
|
|
3
|
-
import {
|
|
4
|
-
import { uniqueBy } from "
|
|
1
|
+
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
import { ASTUtils } from "../../utils/ast-utils.js";
|
|
3
|
+
import { getDocsUrl } from "../../utils/get-docs-url.js";
|
|
4
|
+
import { uniqueBy } from "../../utils/unique-by.js";
|
|
5
|
+
import { detectTanstackQueryImports } from "../../utils/detect-react-query-imports.js";
|
|
5
6
|
import { ExhaustiveDepsUtils } from "./exhaustive-deps.utils.js";
|
|
6
7
|
const QUERY_KEY = "queryKey";
|
|
7
8
|
const QUERY_FN = "queryFn";
|
|
8
9
|
const name = "exhaustive-deps";
|
|
10
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
9
11
|
const rule = createRule({
|
|
10
12
|
name,
|
|
11
13
|
meta: {
|
|
@@ -23,7 +25,7 @@ const rule = createRule({
|
|
|
23
25
|
schema: []
|
|
24
26
|
},
|
|
25
27
|
defaultOptions: [],
|
|
26
|
-
create: (context) => {
|
|
28
|
+
create: detectTanstackQueryImports((context) => {
|
|
27
29
|
return {
|
|
28
30
|
Property: (node) => {
|
|
29
31
|
if (!ASTUtils.isObjectExpression(node.parent) || !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)) {
|
|
@@ -105,7 +107,7 @@ const rule = createRule({
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
};
|
|
108
|
-
}
|
|
110
|
+
})
|
|
109
111
|
});
|
|
110
112
|
export {
|
|
111
113
|
name,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustive-deps.rule.js","sources":["../../../../src/rules/exhaustive-deps/exhaustive-deps.rule.ts"],"sourcesContent":["import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { uniqueBy } from '../../utils/unique-by'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\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\nconst createRule = ESLintUtils.RuleCreator(getDocsUrl)\n\nexport const rule = 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: detectTanstackQueryImports((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":";;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;AAEV,MAAM,OAAO;AAEpB,MAAM,aAAa,YAAY,YAAY,UAAU;AAE9C,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,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;"}
|
package/dist/esm/rules/{exhaustive-deps.utils.js → exhaustive-deps/exhaustive-deps.utils.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
-
import { ASTUtils } from "
|
|
2
|
+
import { ASTUtils } from "../../utils/ast-utils.js";
|
|
3
3
|
const ExhaustiveDepsUtils = {
|
|
4
4
|
isRelevantReference(params) {
|
|
5
5
|
const { reference, scopeManager, context } = params;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exhaustive-deps.utils.js","sources":["../../../../src/rules/exhaustive-deps/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,9 +1,11 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
-
import {
|
|
1
|
+
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
|
+
import { getDocsUrl } from "../../utils/get-docs-url.js";
|
|
3
3
|
import { ASTUtils } from "../../utils/ast-utils.js";
|
|
4
|
+
import { detectTanstackQueryImports } from "../../utils/detect-react-query-imports.js";
|
|
4
5
|
import { NoRestDestructuringUtils } from "./no-rest-destructuring.utils.js";
|
|
5
6
|
const name = "no-rest-destructuring";
|
|
6
7
|
const queryHooks = ["useQuery", "useQueries", "useInfiniteQuery"];
|
|
8
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
7
9
|
const rule = createRule({
|
|
8
10
|
name,
|
|
9
11
|
meta: {
|
|
@@ -18,7 +20,7 @@ const rule = createRule({
|
|
|
18
20
|
schema: []
|
|
19
21
|
},
|
|
20
22
|
defaultOptions: [],
|
|
21
|
-
create: (context, _, helpers) => {
|
|
23
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
22
24
|
return {
|
|
23
25
|
CallExpression: (node) => {
|
|
24
26
|
if (!ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) || !helpers.isTanstackQueryImport(node.callee) || node.parent.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
@@ -50,7 +52,7 @@ const rule = createRule({
|
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
|
-
}
|
|
55
|
+
})
|
|
54
56
|
});
|
|
55
57
|
export {
|
|
56
58
|
name,
|
|
@@ -0,0 +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'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nconst createRule = ESLintUtils.RuleCreator(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' 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: 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 (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;AAEhE,MAAM,aAAa,YAAY,YAAY,UAAU;AAE9C,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,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,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,EACF,CACD;AACH,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-rest-destructuring.utils.js","sources":["../../../../src/rules/no-rest-destructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"names":[],"mappings":";AAGO,MAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AAClD,QAAA,KAAK,SAAS,eAAe,eAAe;AACvC,aAAA;AAAA,IACT;AACO,WAAA,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,eAAe,WAAW;AAAA,EAC1E;AACF;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
export declare const name = "stable-query-client";
|
|
3
|
-
export declare const rule: ESLintUtils.RuleModule<string,
|
|
3
|
+
export declare const rule: ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
1
|
+
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
2
2
|
import { ASTUtils } from "../../utils/ast-utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getDocsUrl } from "../../utils/get-docs-url.js";
|
|
4
|
+
import { detectTanstackQueryImports } from "../../utils/detect-react-query-imports.js";
|
|
4
5
|
const name = "stable-query-client";
|
|
6
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
5
7
|
const rule = createRule({
|
|
6
8
|
name,
|
|
7
9
|
meta: {
|
|
@@ -22,7 +24,7 @@ const rule = createRule({
|
|
|
22
24
|
schema: []
|
|
23
25
|
},
|
|
24
26
|
defaultOptions: [],
|
|
25
|
-
create: (context, _, helpers) => {
|
|
27
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
26
28
|
return {
|
|
27
29
|
NewExpression: (node) => {
|
|
28
30
|
if (node.callee.type !== AST_NODE_TYPES.Identifier || node.callee.name !== "QueryClient" || node.parent.type !== AST_NODE_TYPES.VariableDeclarator || !helpers.isSpecificTanstackQueryImport(
|
|
@@ -56,7 +58,7 @@ const rule = createRule({
|
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
|
-
}
|
|
61
|
+
})
|
|
60
62
|
});
|
|
61
63
|
export {
|
|
62
64
|
name,
|
|
@@ -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 {
|
|
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, ESLintUtils } from '@typescript-eslint/utils'\nimport { ASTUtils } from '../../utils/ast-utils'\nimport { getDocsUrl } from '../../utils/get-docs-url'\nimport { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'\nimport type { TSESLint } from '@typescript-eslint/utils'\n\nexport const name = 'stable-query-client'\n\nconst createRule = ESLintUtils.RuleCreator(getDocsUrl)\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' 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: detectTanstackQueryImports((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":";;;;AAMO,MAAM,OAAO;AAEpB,MAAM,aAAa,YAAY,YAAY,UAAU;AAE9C,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,QACR;AAAA,QACA;AAAA,MAAA,EACA,KAAK,IAAI;AAAA,MACX,OAAO;AAAA,IACT;AAAA,IACA,gBAAgB;AAAA,IAChB,SAAS;AAAA,IACT,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,QAAQ,2BAA2B,CAAC,SAAS,GAAG,YAAY;AACnD,WAAA;AAAA,MACL,eAAe,CAAC,SAAS;AACvB,YACE,KAAK,OAAO,SAAS,eAAe,cACpC,KAAK,OAAO,SAAS,iBACrB,KAAK,OAAO,SAAS,eAAe,sBACpC,CAAC,QAAQ;AAAA,UACP,KAAK;AAAA,UACL;AAAA,QAAA,GAEF;AACA;AAAA,QACF;AAEM,cAAA,aAAa,SAAS,oBAAoB,OAAO;AACjD,cAAA,0BAAyB,yCAAY,WAAU;AAErD,YACE,CAAC,SAAS,gCAAgC,yCAAY,EAAE,KACxD,wBACA;AACA;AAAA,QACF;AAEA,gBAAQ,OAAO;AAAA,UACb,MAAM,KAAK;AAAA,UACX,WAAW;AAAA,UACX,MAAM,MAAM;AACJ,kBAAA,EAAE,OAAW,IAAA;AAEnB,gBAAI,OAAO,GAAG,SAAS,eAAe,YAAY;AAChD;AAAA,YACF;AAEA,kBAAM,WAAW,QAAQ,cAAc,EAAE,QAAQ,IAAI;AAC/C,kBAAA,eAAe,OAAO,GAAG;AAE/B,mBAAO,CAAC,UAA8B;AACpC,qBAAO,MAAM;AAAA,gBACX,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC;AAAA,gBACjC,IAAI,YAAY,4BAA4B,QAAQ;AAAA,cAAA;AAAA,YACtD;AAAA,UACF,GACC;AAAA,QAAA,CACJ;AAAA,MACH;AAAA,IAAA;AAAA,EACF,CACD;AACH,CAAC;"}
|
package/dist/esm/rules.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const rules: Record<string, ESLintUtils.RuleModule<string,
|
|
2
|
+
export declare const rules: Record<string, ESLintUtils.RuleModule<string, ReadonlyArray<unknown>, ESLintUtils.RuleListener>>;
|
package/dist/esm/rules.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { name, rule } from "./rules/exhaustive-deps.rule.js";
|
|
1
|
+
import { name, rule } from "./rules/exhaustive-deps/exhaustive-deps.rule.js";
|
|
2
2
|
import { name as name$1, rule as rule$1 } from "./rules/stable-query-client/stable-query-client.rule.js";
|
|
3
|
-
import { name as name$2, rule as rule$2 } from "./rules/no-rest-
|
|
3
|
+
import { name as name$2, rule as rule$2 } from "./rules/no-rest-destructuring/no-rest-destructuring.rule.js";
|
|
4
4
|
const rules = {
|
|
5
5
|
[name]: rule,
|
|
6
6
|
[name$1]: rule$1,
|
package/dist/esm/rules.js.map
CHANGED
|
@@ -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-
|
|
1
|
+
{"version":3,"file":"rules.js","sources":["../../src/rules.ts"],"sourcesContent":["import * as exhaustiveDeps from './rules/exhaustive-deps/exhaustive-deps.rule'\nimport * as stableQueryClient from './rules/stable-query-client/stable-query-client.rule'\nimport * as noRestDestructuring from './rules/no-rest-destructuring/no-rest-destructuring.rule'\nimport type { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const rules: Record<\n string,\n ESLintUtils.RuleModule<\n string,\n ReadonlyArray<unknown>,\n ESLintUtils.RuleListener\n >\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,QAOT;AAAA,EACF,CAACA,IAAmB,GAAGC;AAAAA,EACvB,CAACC,MAAsB,GAAGC;AAAAA,EAC1B,CAACC,MAAwB,GAAGC;AAC9B;"}
|
|
@@ -7,6 +7,6 @@ type Helpers = {
|
|
|
7
7
|
isSpecificTanstackQueryImport: (node: TSESTree.Identifier, source: string) => boolean;
|
|
8
8
|
isTanstackQueryImport: (node: TSESTree.Identifier) => boolean;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type EnhancedCreate = (context: Context, options: Options, helpers: Helpers) => ReturnType<Create>;
|
|
11
11
|
export declare function detectTanstackQueryImports(create: EnhancedCreate): Create;
|
|
12
12
|
export {};
|
|
@@ -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\
|
|
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\ntype 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,mBAC3C,UAAU,OAAO,SACf,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;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDocsUrl: (ruleName: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-docs-url.js","sources":["../../../src/utils/get-docs-url.ts"],"sourcesContent":["export const getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/latest/docs/eslint/${ruleName}`\n"],"names":[],"mappings":"AAAO,MAAM,aAAa,CAAC,aACzB,iDAAiD,QAAQ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleTester } from '@typescript-eslint/rule-tester'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { rule } from '../rules/exhaustive-deps/exhaustive-deps.rule'
|
|
3
|
+
import { normalizeIndent } from './test-utils'
|
|
4
4
|
|
|
5
5
|
const ruleTester = new RuleTester({
|
|
6
6
|
parser: '@typescript-eslint/parser',
|
|
@@ -23,7 +23,6 @@ ruleTester.run('exhaustive-deps', rule, {
|
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
name: 'should pass when deps are passed in template literal',
|
|
26
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
27
26
|
code: 'useQuery({ queryKey: [`entity/${id}`], queryFn: () => api.getEntity(id) });',
|
|
28
27
|
},
|
|
29
28
|
{
|
|
@@ -464,7 +463,6 @@ ruleTester.run('exhaustive-deps', rule, {
|
|
|
464
463
|
suggestions: [
|
|
465
464
|
{
|
|
466
465
|
messageId: 'fixTo',
|
|
467
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
468
466
|
data: { result: '["entity/${id}", id]' },
|
|
469
467
|
output: normalizeIndent`
|
|
470
468
|
const id = 1;
|
|
@@ -489,7 +487,6 @@ ruleTester.run('exhaustive-deps', rule, {
|
|
|
489
487
|
suggestions: [
|
|
490
488
|
{
|
|
491
489
|
messageId: 'fixTo',
|
|
492
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
493
490
|
data: { result: '[`entity/${a}`, b]' },
|
|
494
491
|
output: normalizeIndent`
|
|
495
492
|
const a = 1;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleTester } from '@typescript-eslint/rule-tester'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { rule } from '../rules/no-rest-destructuring/no-rest-destructuring.rule'
|
|
3
|
+
import { normalizeIndent } from './test-utils'
|
|
4
4
|
|
|
5
5
|
const ruleTester = new RuleTester({
|
|
6
6
|
parser: '@typescript-eslint/parser',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RuleTester } from '@typescript-eslint/rule-tester'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { rule } from '../rules/stable-query-client/stable-query-client.rule'
|
|
3
|
+
import { normalizeIndent } from './test-utils'
|
|
4
4
|
|
|
5
5
|
const ruleTester = new RuleTester({
|
|
6
6
|
parser: '@typescript-eslint/parser',
|
package/src/configs.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { rules } from './rules'
|
|
2
|
-
import type {
|
|
2
|
+
import type { ESLintUtils } from '@typescript-eslint/utils'
|
|
3
3
|
|
|
4
4
|
function generateRecommendedConfig(
|
|
5
|
-
allRules: Record<
|
|
5
|
+
allRules: Record<
|
|
6
|
+
string,
|
|
7
|
+
ESLintUtils.RuleModule<
|
|
8
|
+
string,
|
|
9
|
+
ReadonlyArray<unknown>,
|
|
10
|
+
ESLintUtils.RuleListener
|
|
11
|
+
>
|
|
12
|
+
>,
|
|
6
13
|
) {
|
|
7
14
|
return Object.entries(allRules).reduce(
|
|
8
15
|
// @ts-expect-error
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
-
import { ASTUtils } from '
|
|
3
|
-
import {
|
|
4
|
-
import { uniqueBy } from '
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'
|
|
2
|
+
import { ASTUtils } from '../../utils/ast-utils'
|
|
3
|
+
import { getDocsUrl } from '../../utils/get-docs-url'
|
|
4
|
+
import { uniqueBy } from '../../utils/unique-by'
|
|
5
|
+
import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
|
|
5
6
|
import { ExhaustiveDepsUtils } from './exhaustive-deps.utils'
|
|
6
|
-
import type {
|
|
7
|
+
import type { TSESLint } from '@typescript-eslint/utils'
|
|
7
8
|
|
|
8
9
|
const QUERY_KEY = 'queryKey'
|
|
9
10
|
const QUERY_FN = 'queryFn'
|
|
10
11
|
|
|
11
12
|
export const name = 'exhaustive-deps'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ESLintUtils.RuleListener
|
|
17
|
-
> = createRule({
|
|
14
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl)
|
|
15
|
+
|
|
16
|
+
export const rule = createRule({
|
|
18
17
|
name,
|
|
19
18
|
meta: {
|
|
20
19
|
type: 'problem',
|
|
@@ -32,7 +31,7 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
32
31
|
},
|
|
33
32
|
defaultOptions: [],
|
|
34
33
|
|
|
35
|
-
create: (context) => {
|
|
34
|
+
create: detectTanstackQueryImports((context) => {
|
|
36
35
|
return {
|
|
37
36
|
Property: (node) => {
|
|
38
37
|
if (
|
|
@@ -153,5 +152,5 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
153
152
|
}
|
|
154
153
|
},
|
|
155
154
|
}
|
|
156
|
-
},
|
|
155
|
+
}),
|
|
157
156
|
})
|
package/src/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.rule.ts
RENAMED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
-
import {
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'
|
|
2
|
+
import { getDocsUrl } from '../../utils/get-docs-url'
|
|
3
3
|
import { ASTUtils } from '../../utils/ast-utils'
|
|
4
|
+
import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
|
|
4
5
|
import { NoRestDestructuringUtils } from './no-rest-destructuring.utils'
|
|
5
|
-
import type { ESLintUtils } from '@typescript-eslint/utils'
|
|
6
6
|
|
|
7
7
|
export const name = 'no-rest-destructuring'
|
|
8
8
|
|
|
9
9
|
const queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ESLintUtils.RuleListener
|
|
15
|
-
> = createRule({
|
|
11
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl)
|
|
12
|
+
|
|
13
|
+
export const rule = createRule({
|
|
16
14
|
name,
|
|
17
15
|
meta: {
|
|
18
16
|
type: 'problem',
|
|
@@ -27,7 +25,7 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
27
25
|
},
|
|
28
26
|
defaultOptions: [],
|
|
29
27
|
|
|
30
|
-
create: (context, _, helpers) => {
|
|
28
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
31
29
|
return {
|
|
32
30
|
CallExpression: (node) => {
|
|
33
31
|
if (
|
|
@@ -65,5 +63,5 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
65
63
|
})
|
|
66
64
|
},
|
|
67
65
|
}
|
|
68
|
-
},
|
|
66
|
+
}),
|
|
69
67
|
})
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'
|
|
2
2
|
import { ASTUtils } from '../../utils/ast-utils'
|
|
3
|
-
import {
|
|
3
|
+
import { getDocsUrl } from '../../utils/get-docs-url'
|
|
4
|
+
import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
|
|
4
5
|
import type { TSESLint } from '@typescript-eslint/utils'
|
|
5
|
-
import type { ESLintUtils } from '@typescript-eslint/utils'
|
|
6
6
|
|
|
7
7
|
export const name = 'stable-query-client'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ESLintUtils.RuleListener
|
|
13
|
-
> = createRule({
|
|
9
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl)
|
|
10
|
+
|
|
11
|
+
export const rule = createRule({
|
|
14
12
|
name,
|
|
15
13
|
meta: {
|
|
16
14
|
type: 'problem',
|
|
@@ -31,7 +29,7 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
31
29
|
},
|
|
32
30
|
defaultOptions: [],
|
|
33
31
|
|
|
34
|
-
create: (context, _, helpers) => {
|
|
32
|
+
create: detectTanstackQueryImports((context, _, helpers) => {
|
|
35
33
|
return {
|
|
36
34
|
NewExpression: (node) => {
|
|
37
35
|
if (
|
|
@@ -79,5 +77,5 @@ export const rule: ESLintUtils.RuleModule<
|
|
|
79
77
|
})
|
|
80
78
|
},
|
|
81
79
|
}
|
|
82
|
-
},
|
|
80
|
+
}),
|
|
83
81
|
})
|
package/src/rules.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import * as exhaustiveDeps from './rules/exhaustive-deps.rule'
|
|
1
|
+
import * as exhaustiveDeps from './rules/exhaustive-deps/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-
|
|
3
|
+
import * as noRestDestructuring from './rules/no-rest-destructuring/no-rest-destructuring.rule'
|
|
4
4
|
import type { ESLintUtils } from '@typescript-eslint/utils'
|
|
5
5
|
|
|
6
6
|
export const rules: Record<
|
|
7
7
|
string,
|
|
8
|
-
ESLintUtils.RuleModule<
|
|
8
|
+
ESLintUtils.RuleModule<
|
|
9
|
+
string,
|
|
10
|
+
ReadonlyArray<unknown>,
|
|
11
|
+
ESLintUtils.RuleListener
|
|
12
|
+
>
|
|
9
13
|
> = {
|
|
10
14
|
[exhaustiveDeps.name]: exhaustiveDeps.rule,
|
|
11
15
|
[stableQueryClient.name]: stableQueryClient.rule,
|
|
@@ -1 +0,0 @@
|
|
|
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,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AAY,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 +0,0 @@
|
|
|
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;;"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-rest-destructuring.utils.cjs","sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"names":["AST_NODE_TYPES"],"mappings":";;;AAGO,MAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AAClD,QAAA,KAAK,SAASA,MAAA,eAAe,eAAe;AACvC,aAAA;AAAA,IACT;AACO,WAAA,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAASA,qBAAe,WAAW;AAAA,EAC1E;AACF;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const utils = require("@typescript-eslint/utils");
|
|
4
|
-
const detectReactQueryImports = require("./detect-react-query-imports.cjs");
|
|
5
|
-
const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
|
|
6
|
-
function createRule({ create, ...rest }) {
|
|
7
|
-
return utils.ESLintUtils.RuleCreator(getDocsUrl)({
|
|
8
|
-
...rest,
|
|
9
|
-
create: detectReactQueryImports.detectTanstackQueryImports(create)
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
exports.createRule = createRule;
|
|
13
|
-
//# sourceMappingURL=create-rule.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-rule.cjs","sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/latest/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"names":["ESLintUtils","detectTanstackQueryImports"],"mappings":";;;;AAIA,MAAM,aAAa,CAAC,aAClB,iDAAiD,QAAQ;AASpD,SAAS,WAAW,EAAE,QAAQ,GAAG,QAAoB;AACnD,SAAAA,MAAA,YAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,QAAQC,mDAA2B,MAAM;AAAA,EAAA,CAC1C;AACH;;"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
import type { EnhancedCreate } from './detect-react-query-imports.cjs';
|
|
3
|
-
type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
|
|
4
|
-
create: EnhancedCreate;
|
|
5
|
-
};
|
|
6
|
-
export declare function createRule({ create, ...rest }: EslintRule): ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
|
|
7
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function normalizeIndent(template: TemplateStringsArray): string;
|
|
@@ -1 +0,0 @@
|
|
|
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;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,iBAChD;AACA,yBAAe,aAAa;AAAA,QAC9B;AAEI,YAAA,aAAa,SAAS,eAAe,YAAY;AAC7C,gBAAA,aAAa,SAAS,oCAAo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M,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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-rest-destructuring.utils.js","sources":["../../../../src/rules/no-rest-desctructuring/no-rest-destructuring.utils.ts"],"sourcesContent":["import { AST_NODE_TYPES } from '@typescript-eslint/utils'\nimport type { TSESTree } from '@typescript-eslint/utils'\n\nexport const NoRestDestructuringUtils = {\n isObjectRestDestructuring(node: TSESTree.Node): boolean {\n if (node.type !== AST_NODE_TYPES.ObjectPattern) {\n return false\n }\n return node.properties.some((p) => p.type === AST_NODE_TYPES.RestElement)\n },\n}\n"],"names":[],"mappings":";AAGO,MAAM,2BAA2B;AAAA,EACtC,0BAA0B,MAA8B;AAClD,QAAA,KAAK,SAAS,eAAe,eAAe;AACvC,aAAA;AAAA,IACT;AACO,WAAA,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,eAAe,WAAW;AAAA,EAC1E;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
import type { EnhancedCreate } from './detect-react-query-imports.js';
|
|
3
|
-
type EslintRule = Omit<Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0], 'create'> & {
|
|
4
|
-
create: EnhancedCreate;
|
|
5
|
-
};
|
|
6
|
-
export declare function createRule({ create, ...rest }: EslintRule): ESLintUtils.RuleModule<string, readonly unknown[], ESLintUtils.RuleListener>;
|
|
7
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
import { detectTanstackQueryImports } from "./detect-react-query-imports.js";
|
|
3
|
-
const getDocsUrl = (ruleName) => `https://tanstack.com/query/latest/docs/eslint/${ruleName}`;
|
|
4
|
-
function createRule({ create, ...rest }) {
|
|
5
|
-
return ESLintUtils.RuleCreator(getDocsUrl)({
|
|
6
|
-
...rest,
|
|
7
|
-
create: detectTanstackQueryImports(create)
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
createRule
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=create-rule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-rule.js","sources":["../../../src/utils/create-rule.ts"],"sourcesContent":["import { ESLintUtils } from '@typescript-eslint/utils'\nimport { detectTanstackQueryImports } from './detect-react-query-imports'\nimport type { EnhancedCreate } from './detect-react-query-imports'\n\nconst getDocsUrl = (ruleName: string): string =>\n `https://tanstack.com/query/latest/docs/eslint/${ruleName}`\n\ntype EslintRule = Omit<\n Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],\n 'create'\n> & {\n create: EnhancedCreate\n}\n\nexport function createRule({ create, ...rest }: EslintRule) {\n return ESLintUtils.RuleCreator(getDocsUrl)({\n ...rest,\n create: detectTanstackQueryImports(create),\n })\n}\n"],"names":[],"mappings":";;AAIA,MAAM,aAAa,CAAC,aAClB,iDAAiD,QAAQ;AASpD,SAAS,WAAW,EAAE,QAAQ,GAAG,QAAoB;AACnD,SAAA,YAAY,YAAY,UAAU,EAAE;AAAA,IACzC,GAAG;AAAA,IACH,QAAQ,2BAA2B,MAAM;AAAA,EAAA,CAC1C;AACH;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function normalizeIndent(template: TemplateStringsArray): string;
|
package/src/utils/create-rule.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils'
|
|
2
|
-
import { detectTanstackQueryImports } from './detect-react-query-imports'
|
|
3
|
-
import type { EnhancedCreate } from './detect-react-query-imports'
|
|
4
|
-
|
|
5
|
-
const getDocsUrl = (ruleName: string): string =>
|
|
6
|
-
`https://tanstack.com/query/latest/docs/eslint/${ruleName}`
|
|
7
|
-
|
|
8
|
-
type EslintRule = Omit<
|
|
9
|
-
Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0],
|
|
10
|
-
'create'
|
|
11
|
-
> & {
|
|
12
|
-
create: EnhancedCreate
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createRule({ create, ...rest }: EslintRule) {
|
|
16
|
-
return ESLintUtils.RuleCreator(getDocsUrl)({
|
|
17
|
-
...rest,
|
|
18
|
-
create: detectTanstackQueryImports(create),
|
|
19
|
-
})
|
|
20
|
-
}
|
/package/dist/cjs/rules/{exhaustive-deps.utils.d.cts → exhaustive-deps/exhaustive-deps.utils.d.cts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/esm/rules/{exhaustive-deps.utils.d.ts → exhaustive-deps/exhaustive-deps.utils.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.utils.ts
RENAMED
|
File without changes
|