Skip to content

Commit

Permalink
fix(eslint-plugin-query): handle non-null at then end of var in exhau…
Browse files Browse the repository at this point in the history
…stive-deps (#8385)
  • Loading branch information
imranbarbhuiya authored Dec 2, 2024
1 parent 12b6782 commit d9d2728
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ ruleTester.run('exhaustive-deps', rule, {
}
`,
},
{
name: 'should pass with optional chaining as key and non-null assertion at the end of the variable in queryFn',
code: `
function useTest(data?: any) {
return useQuery({
queryKey: ['query-name', data?.address],
queryFn: async () => sendQuery(data!.address!),
enabled: !!data?.address,
})
}
`,
},
],
invalid: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-query/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export const ASTUtils = {
sourceCode: Readonly<TSESLint.SourceCode>,
) {
return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
/(\?\.|!\.)/g,
'.',
/(?:\?(\.)|!)/g,
'$1',
)
},
isValidReactComponentOrHookName(
Expand Down

0 comments on commit d9d2728

Please sign in to comment.