Skip to content

Commit

Permalink
fix(eslint-plugin-query): test for FunctionExpression syntax (#7213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Newbie012 committed Apr 2, 2024
1 parent a9648ba commit 1e3f791
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
Expand Up @@ -726,5 +726,24 @@ ruleTester.run('exhaustive-deps', rule, {
},
],
},
{
name: 'should fail if queryFn is invalid while using FunctionExpression syntax',
code: normalizeIndent`
const id = 1;
useQuery({
queryKey: [],
queryFn() {
Promise.resolve(id)
}
})
`,
errors: [
{
messageId: 'missingDeps',
data: { deps: 'id' },
},
],
},
],
})
Expand Up @@ -55,7 +55,10 @@ export const rule = createRule({
scopeManager === null ||
queryKey === undefined ||
queryFn === undefined ||
queryFn.value.type !== AST_NODE_TYPES.ArrowFunctionExpression
!ASTUtils.isNodeOfOneOf(queryFn.value, [
AST_NODE_TYPES.ArrowFunctionExpression,
AST_NODE_TYPES.FunctionExpression,
])
) {
return
}
Expand Down

0 comments on commit 1e3f791

Please sign in to comment.