Skip to content

Commit d9d2728

Browse files
authoredDec 2, 2024··
fix(eslint-plugin-query): handle non-null at then end of var in exhaustive-deps (#8385)
1 parent 12b6782 commit d9d2728

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎packages/eslint-plugin-query/src/__tests__/exhaustive-deps.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,18 @@ ruleTester.run('exhaustive-deps', rule, {
497497
}
498498
`,
499499
},
500+
{
501+
name: 'should pass with optional chaining as key and non-null assertion at the end of the variable in queryFn',
502+
code: `
503+
function useTest(data?: any) {
504+
return useQuery({
505+
queryKey: ['query-name', data?.address],
506+
queryFn: async () => sendQuery(data!.address!),
507+
enabled: !!data?.address,
508+
})
509+
}
510+
`,
511+
},
500512
],
501513
invalid: [
502514
{

‎packages/eslint-plugin-query/src/utils/ast-utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ export const ASTUtils = {
234234
sourceCode: Readonly<TSESLint.SourceCode>,
235235
) {
236236
return ASTUtils.mapKeyNodeToText(node, sourceCode).replace(
237-
/(\?\.|!\.)/g,
238-
'.',
237+
/(?:\?(\.)|!)/g,
238+
'$1',
239239
)
240240
},
241241
isValidReactComponentOrHookName(

0 commit comments

Comments
 (0)
Please sign in to comment.