Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export const rule = createRule({

let queryKeyNode = queryKey.value

if (
queryKeyNode.type === AST_NODE_TYPES.TSAsExpression &&
queryKeyNode.expression.type === AST_NODE_TYPES.ArrayExpression
) {
queryKeyNode = queryKeyNode.expression
}

if (queryKeyNode.type === AST_NODE_TYPES.Identifier) {
const expression = ASTUtils.getReferencedExpressionByIdentifier({
context,
Expand All @@ -80,7 +87,7 @@ export const rule = createRule({
const relevantRefs = refs.filter((ref) => {
return (
ref.identifier.name !== 'undefined' &&
ref.resolved?.defs.every((def) => def.type !== 'ClassName')
ref.identifier.parent?.type !== AST_NODE_TYPES.NewExpression
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ ruleTester.run('exhaustive-deps', rule, {
})
`,
},
{
name: 'should not treat new Error as missing dependency',
code: normalizeIndent`
useQuery({
queryKey: ['foo'],
queryFn: () => Promise.reject(new Error('1')),
})
`,
},
{
name: 'should see id when there is a const assertion',
code: normalizeIndent`
const useX = (id: number) => {
return useQuery({
queryKey: ['foo', id] as const,
queryFn: async () => id,
})
}
`,
},
],
invalid: [
{
Expand Down