@tanstack/eslint-plugin-query 5.18.1 → 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 +1 -0
- package/dist/cjs/configs.cjs.map +1 -1
- package/dist/cjs/configs.d.cts +2 -1
- package/dist/cjs/rules/{exhaustive-deps.rule.cjs → exhaustive-deps/exhaustive-deps.rule.cjs} +10 -8
- 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} +2 -3
- 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 +8 -7
- 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 +8 -7
- 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 +2 -5
- package/dist/cjs/utils/ast-utils.cjs +1 -1
- package/dist/cjs/utils/ast-utils.cjs.map +1 -1
- package/dist/cjs/utils/ast-utils.d.cts +3 -4
- package/dist/cjs/utils/detect-react-query-imports.cjs +1 -2
- 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 -1
- package/dist/esm/configs.js +1 -0
- 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} +10 -8
- 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} +2 -3
- 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 +8 -7
- 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 +8 -7
- package/dist/esm/rules/stable-query-client/stable-query-client.rule.js.map +1 -1
- package/dist/esm/rules.d.ts +2 -5
- package/dist/esm/rules.js +2 -2
- package/dist/esm/rules.js.map +1 -1
- package/dist/esm/utils/ast-utils.d.ts +3 -4
- package/dist/esm/utils/ast-utils.js +1 -1
- package/dist/esm/utils/ast-utils.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 +1 -2
- 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 +3 -2
- package/src/__tests__/exhaustive-deps.test.ts +4 -7
- package/src/{rules/no-rest-desctructuring → __tests__}/no-rest-destructuring.test.ts +4 -4
- package/src/{rules/stable-query-client → __tests__}/stable-query-client.test.ts +4 -4
- package/src/configs.ts +10 -2
- package/src/rules/{exhaustive-deps.rule.ts → exhaustive-deps/exhaustive-deps.rule.ts} +11 -9
- package/src/rules/{exhaustive-deps.utils.ts → exhaustive-deps/exhaustive-deps.utils.ts} +2 -2
- package/src/rules/{no-rest-desctructuring → no-rest-destructuring}/no-rest-destructuring.rule.ts +10 -7
- package/src/rules/stable-query-client/stable-query-client.rule.ts +10 -7
- package/src/rules.ts +11 -3
- package/src/utils/ast-utils.ts +3 -7
- package/src/utils/detect-react-query-imports.ts +2 -2
- 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 -2
- 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 -2
- 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/src/utils/ast-utils.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
2
|
import { uniqueBy } from './unique-by'
|
|
3
3
|
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
|
|
4
|
-
import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'
|
|
5
4
|
|
|
6
5
|
export const ASTUtils = {
|
|
7
6
|
isNodeOfOneOf<T extends AST_NODE_TYPES>(
|
|
@@ -212,7 +211,7 @@ export const ASTUtils = {
|
|
|
212
211
|
)
|
|
213
212
|
},
|
|
214
213
|
getFunctionAncestor(
|
|
215
|
-
context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>,
|
|
214
|
+
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>,
|
|
216
215
|
) {
|
|
217
216
|
for (const ancestor of context.getAncestors()) {
|
|
218
217
|
if (ancestor.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
@@ -236,7 +235,7 @@ export const ASTUtils = {
|
|
|
236
235
|
},
|
|
237
236
|
getReferencedExpressionByIdentifier(params: {
|
|
238
237
|
node: TSESTree.Node
|
|
239
|
-
context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>
|
|
238
|
+
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>
|
|
240
239
|
}) {
|
|
241
240
|
const { node, context } = params
|
|
242
241
|
|
|
@@ -254,10 +253,7 @@ export const ASTUtils = {
|
|
|
254
253
|
getClosestVariableDeclarator(node: TSESTree.Node) {
|
|
255
254
|
let currentNode: TSESTree.Node | undefined = node
|
|
256
255
|
|
|
257
|
-
while (
|
|
258
|
-
currentNode !== undefined &&
|
|
259
|
-
currentNode.type !== AST_NODE_TYPES.Program
|
|
260
|
-
) {
|
|
256
|
+
while (currentNode.type !== AST_NODE_TYPES.Program) {
|
|
261
257
|
if (currentNode.type === AST_NODE_TYPES.VariableDeclarator) {
|
|
262
258
|
return currentNode
|
|
263
259
|
}
|
|
@@ -15,7 +15,7 @@ type Helpers = {
|
|
|
15
15
|
isTanstackQueryImport: (node: TSESTree.Identifier) => boolean
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
type EnhancedCreate = (
|
|
19
19
|
context: Context,
|
|
20
20
|
options: Options,
|
|
21
21
|
helpers: Helpers,
|
|
@@ -30,7 +30,7 @@ export function detectTanstackQueryImports(create: EnhancedCreate): Create {
|
|
|
30
30
|
return !!tanstackQueryImportSpecifiers.find((specifier) => {
|
|
31
31
|
if (
|
|
32
32
|
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&
|
|
33
|
-
specifier.parent
|
|
33
|
+
specifier.parent.type ===
|
|
34
34
|
TSESTree.AST_NODE_TYPES.ImportDeclaration &&
|
|
35
35
|
specifier.parent.source.value === source
|
|
36
36
|
) {
|
|
@@ -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 { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"names":["createRule","ASTUtils","AST_NODE_TYPES","ExhaustiveDepsUtils","uniqueBy"],"mappings":"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"}
|
|
@@ -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,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAASC,MAAAA,eAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;;AAC1D,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAASA,MAAAA,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAASA,MAAe,eAAA,kBACzC,WAAW,KAAK,OAAO,SAASA,MAAAA,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;;"}
|
|
@@ -1 +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'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Disallows rest destructuring in queries',\n recommended: 'warn',\n },\n messages: {\n objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`,\n },\n schema: [],\n },\n defaultOptions: [],\n\n create(context, _, helpers) {\n return {\n CallExpression(node) {\n if (\n !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||\n !helpers.isTanstackQueryImport(node.callee) ||\n node.parent?.type !== AST_NODE_TYPES.VariableDeclarator\n ) {\n return\n }\n\n const returnValue = node.parent.id\n if (node.callee.name !== 'useQueries') {\n if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {\n context.report({\n node: node.parent,\n messageId: 'objectRestDestructure',\n })\n }\n return\n }\n\n if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {\n return\n }\n returnValue.elements.forEach((queryResult) => {\n if (queryResult === null) {\n return\n }\n if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {\n context.report({\n node: queryResult,\n messageId: 'objectRestDestructure',\n })\n }\n })\n },\n }\n },\n})\n"],"names":["createRule","ASTUtils","AST_NODE_TYPES","NoRestDestructuringUtils"],"mappings":";;;;;;AAKO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,OAAOA,WAAAA,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,uBAAuB;AAAA,IACzB;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS,GAAG,SAAS;AACnB,WAAA;AAAA,MACL,eAAe,MAAM;;AACnB,YACE,CAACC,SAAS,SAAA,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAASC,qBAAe,oBACrC;AACA;AAAA,QACF;AAEM,cAAA,cAAc,KAAK,OAAO;AAC5B,YAAA,KAAK,OAAO,SAAS,cAAc;AACjC,cAAAC,0BAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AACA;AAAA,QACF;AAEI,YAAA,YAAY,SAASD,MAAA,eAAe,cAAc;AACpD;AAAA,QACF;AACY,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACI,cAAAC,0BAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AAAA,QAAA,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;;;"}
|
|
@@ -1 +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): import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").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 { TSESLint } from '@typescript-eslint/utils'\n\nconst QUERY_KEY = 'queryKey'\nconst QUERY_FN = 'queryFn'\n\nexport const name = 'exhaustive-deps'\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Exhaustive deps rule for useQuery',\n recommended: 'error',\n },\n messages: {\n missingDeps: `The following dependencies are missing in your queryKey: {{deps}}`,\n fixTo: 'Fix to {{result}}',\n },\n hasSuggestions: true,\n fixable: 'code',\n schema: [],\n },\n defaultOptions: [],\n\n create(context) {\n return {\n Property(node) {\n if (\n node.parent === undefined ||\n !ASTUtils.isObjectExpression(node.parent) ||\n !ASTUtils.isIdentifierWithName(node.key, QUERY_KEY)\n ) {\n return\n }\n\n const scopeManager = context.getSourceCode().scopeManager\n const queryKey = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_KEY,\n )\n const queryFn = ASTUtils.findPropertyWithIdentifierKey(\n node.parent.properties,\n QUERY_FN,\n )\n\n if (\n scopeManager === null ||\n queryKey === undefined ||\n queryFn === undefined ||\n queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression\n ) {\n return\n }\n\n let queryKeyNode = queryKey.value\n\n if (\n queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&\n queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression\n ) {\n queryKeyNode = queryKeyNode.expression\n }\n\n if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {\n const expression = ASTUtils.getReferencedExpressionByIdentifier({\n context,\n node: queryKeyNode,\n })\n\n if (expression?.type === AST_NODE_TYPES.ArrayExpression) {\n queryKeyNode = expression\n }\n }\n\n const sourceCode = context.getSourceCode()\n const queryKeyValue = queryKeyNode\n const externalRefs = ASTUtils.getExternalRefs({\n scopeManager,\n sourceCode,\n node: queryFn.value,\n })\n\n const relevantRefs = externalRefs.filter((reference) =>\n ExhaustiveDepsUtils.isRelevantReference({\n context,\n reference,\n scopeManager,\n }),\n )\n\n const existingKeys = ASTUtils.getNestedIdentifiers(queryKeyValue).map(\n (identifier) => ASTUtils.mapKeyNodeToText(identifier, sourceCode),\n )\n\n const missingRefs = relevantRefs\n .map((ref) => ({\n ref: ref,\n text: ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode),\n }))\n .filter(({ ref, text }) => {\n return (\n !ref.isTypeReference &&\n !ASTUtils.isAncestorIsCallee(ref.identifier) &&\n !existingKeys.some((existingKey) => existingKey === text) &&\n !existingKeys.includes(text.split('.')[0] ?? '')\n )\n })\n .map(({ ref, text }) => ({\n identifier: ref.identifier,\n text: text,\n }))\n\n const uniqueMissingRefs = uniqueBy(missingRefs, (x) => x.text)\n\n if (uniqueMissingRefs.length > 0) {\n const missingAsText = uniqueMissingRefs\n .map((ref) => ASTUtils.mapKeyNodeToText(ref.identifier, sourceCode))\n .join(', ')\n\n const existingWithMissing = sourceCode\n .getText(queryKeyValue)\n .replace(/\\]$/, `, ${missingAsText}]`)\n\n const suggestions: TSESLint.ReportSuggestionArray<string> = []\n\n if (queryKeyNode.type === AST_NODE_TYPES.ArrayExpression) {\n suggestions.push({\n messageId: 'fixTo',\n data: { result: existingWithMissing },\n fix(fixer) {\n return fixer.replaceText(queryKeyValue, existingWithMissing)\n },\n })\n }\n\n context.report({\n node: node,\n messageId: 'missingDeps',\n data: {\n deps: uniqueMissingRefs.map((ref) => ref.text).join(', '),\n },\n suggest: suggestions,\n })\n }\n },\n }\n },\n})\n"],"names":[],"mappings":"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"}
|
|
@@ -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,iBAC9B,eAAU,WAAW,WAArB,mBAA6B,UAAS,eAAe,iBACrD,CAAC,oBAAoB,uBAAuB,SAAS;AAAA,EAEzD;AAAA,EACA,uBAAuB,WAAqC;;AAC1D,UAAM,cAAa,qBAAU,aAAV,mBAAoB,KAAK,OAAzB,mBAA6B;AAEhD,YACE,yCAAY,UAAS,eAAe,wBACpC,gBAAW,SAAX,mBAAiB,UAAS,eAAe,kBACzC,WAAW,KAAK,OAAO,SAAS,eAAe,cAC/C,WAAW,KAAK,OAAO,SAAS;AAAA,EAEpC;AACF;"}
|
|
@@ -1 +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'\n\nexport const name = 'no-rest-destructuring'\n\nconst queryHooks = ['useQuery', 'useQueries', 'useInfiniteQuery']\n\nexport const rule = createRule({\n name,\n meta: {\n type: 'problem',\n docs: {\n description: 'Disallows rest destructuring in queries',\n recommended: 'warn',\n },\n messages: {\n objectRestDestructure: `Object rest destructuring on a query will observe all changes to the query, leading to excessive re-renders.`,\n },\n schema: [],\n },\n defaultOptions: [],\n\n create(context, _, helpers) {\n return {\n CallExpression(node) {\n if (\n !ASTUtils.isIdentifierWithOneOfNames(node.callee, queryHooks) ||\n !helpers.isTanstackQueryImport(node.callee) ||\n node.parent?.type !== AST_NODE_TYPES.VariableDeclarator\n ) {\n return\n }\n\n const returnValue = node.parent.id\n if (node.callee.name !== 'useQueries') {\n if (NoRestDestructuringUtils.isObjectRestDestructuring(returnValue)) {\n context.report({\n node: node.parent,\n messageId: 'objectRestDestructure',\n })\n }\n return\n }\n\n if (returnValue.type !== AST_NODE_TYPES.ArrayPattern) {\n return\n }\n returnValue.elements.forEach((queryResult) => {\n if (queryResult === null) {\n return\n }\n if (NoRestDestructuringUtils.isObjectRestDestructuring(queryResult)) {\n context.report({\n node: queryResult,\n messageId: 'objectRestDestructure',\n })\n }\n })\n },\n }\n },\n})\n"],"names":[],"mappings":";;;;AAKO,MAAM,OAAO;AAEpB,MAAM,aAAa,CAAC,YAAY,cAAc,kBAAkB;AAEzD,MAAM,OAAO,WAAW;AAAA,EAC7B;AAAA,EACA,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aAAa;AAAA,MACb,aAAa;AAAA,IACf;AAAA,IACA,UAAU;AAAA,MACR,uBAAuB;AAAA,IACzB;AAAA,IACA,QAAQ,CAAC;AAAA,EACX;AAAA,EACA,gBAAgB,CAAC;AAAA,EAEjB,OAAO,SAAS,GAAG,SAAS;AACnB,WAAA;AAAA,MACL,eAAe,MAAM;;AACnB,YACE,CAAC,SAAS,2BAA2B,KAAK,QAAQ,UAAU,KAC5D,CAAC,QAAQ,sBAAsB,KAAK,MAAM,OAC1C,UAAK,WAAL,mBAAa,UAAS,eAAe,oBACrC;AACA;AAAA,QACF;AAEM,cAAA,cAAc,KAAK,OAAO;AAC5B,YAAA,KAAK,OAAO,SAAS,cAAc;AACjC,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM,KAAK;AAAA,cACX,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AACA;AAAA,QACF;AAEI,YAAA,YAAY,SAAS,eAAe,cAAc;AACpD;AAAA,QACF;AACY,oBAAA,SAAS,QAAQ,CAAC,gBAAgB;AAC5C,cAAI,gBAAgB,MAAM;AACxB;AAAA,UACF;AACI,cAAA,yBAAyB,0BAA0B,WAAW,GAAG;AACnE,oBAAQ,OAAO;AAAA,cACb,MAAM;AAAA,cACN,WAAW;AAAA,YAAA,CACZ;AAAA,UACH;AAAA,QAAA,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
|
|
@@ -1 +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): import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, readonly unknown[], import("@typescript-eslint/utils/dist/ts-eslint/Rule").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
|