@tanstack/eslint-plugin-query
Advanced tools
Comparing version 5.51.1 to 5.51.7
@@ -45,3 +45,4 @@ import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils"; | ||
AST_NODE_TYPES.ArrowFunctionExpression, | ||
AST_NODE_TYPES.FunctionExpression | ||
AST_NODE_TYPES.FunctionExpression, | ||
AST_NODE_TYPES.ConditionalExpression | ||
])) { | ||
@@ -67,3 +68,3 @@ return; | ||
sourceCode: context.sourceCode, | ||
node: queryFn.value | ||
node: getQueryFnRelevantNode(queryFn) | ||
}); | ||
@@ -75,3 +76,3 @@ const relevantRefs = externalRefs.filter( | ||
scopeManager, | ||
node: queryFn.value | ||
node: getQueryFnRelevantNode(queryFn) | ||
}) | ||
@@ -120,2 +121,11 @@ ); | ||
}); | ||
function getQueryFnRelevantNode(queryFn) { | ||
if (queryFn.value.type !== AST_NODE_TYPES.ConditionalExpression) { | ||
return queryFn.value; | ||
} | ||
if (queryFn.value.consequent.type === AST_NODE_TYPES.Identifier && queryFn.value.consequent.name === "skipToken") { | ||
return queryFn.value.alternate; | ||
} | ||
return queryFn.value.consequent; | ||
} | ||
export { | ||
@@ -122,0 +132,0 @@ name, |
{ | ||
"name": "@tanstack/eslint-plugin-query", | ||
"version": "5.51.1", | ||
"version": "5.51.7", | ||
"description": "ESLint plugin for TanStack Query", | ||
@@ -5,0 +5,0 @@ "author": "Eliya Cohen", |
@@ -405,2 +405,16 @@ import { RuleTester } from '@typescript-eslint/rule-tester' | ||
}, | ||
{ | ||
name: 'queryFn as a ternary expression with dep and a skipToken', | ||
code: normalizeIndent` | ||
import { useQuery, skipToken } from "@tanstack/react-query"; | ||
const fetch = true | ||
function Component({ id }) { | ||
useQuery({ | ||
queryKey: [id], | ||
queryFn: fetch ? () => Promise.resolve(id) : skipToken | ||
}) | ||
} | ||
`, | ||
}, | ||
], | ||
@@ -737,3 +751,23 @@ invalid: [ | ||
}, | ||
{ | ||
name: 'should fail if queryFn is a ternary expression with missing dep and a skipToken', | ||
code: normalizeIndent` | ||
import { useQuery, skipToken } from "@tanstack/react-query"; | ||
const fetch = true | ||
function Component({ id }) { | ||
useQuery({ | ||
queryKey: [], | ||
queryFn: fetch ? () => Promise.resolve(id) : skipToken | ||
}) | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'missingDeps', | ||
data: { deps: 'id' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}) |
@@ -7,3 +7,3 @@ import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils' | ||
import { ExhaustiveDepsUtils } from './exhaustive-deps.utils' | ||
import type { TSESLint } from '@typescript-eslint/utils' | ||
import type { TSESLint, TSESTree } from '@typescript-eslint/utils' | ||
import type { ExtraRuleDocs } from '../../types' | ||
@@ -63,2 +63,3 @@ | ||
AST_NODE_TYPES.FunctionExpression, | ||
AST_NODE_TYPES.ConditionalExpression, | ||
]) | ||
@@ -93,3 +94,3 @@ ) { | ||
sourceCode: context.sourceCode, | ||
node: queryFn.value, | ||
node: getQueryFnRelevantNode(queryFn), | ||
}) | ||
@@ -102,3 +103,3 @@ | ||
scopeManager, | ||
node: queryFn.value, | ||
node: getQueryFnRelevantNode(queryFn), | ||
}), | ||
@@ -168,1 +169,16 @@ ) | ||
}) | ||
function getQueryFnRelevantNode(queryFn: TSESTree.Property) { | ||
if (queryFn.value.type !== AST_NODE_TYPES.ConditionalExpression) { | ||
return queryFn.value | ||
} | ||
if ( | ||
queryFn.value.consequent.type === AST_NODE_TYPES.Identifier && | ||
queryFn.value.consequent.name === 'skipToken' | ||
) { | ||
return queryFn.value.alternate | ||
} | ||
return queryFn.value.consequent | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208902
3311