Skip to content

Commit c232a6f

Browse files
Eliya Cohenautofix-ci[bot]
andauthored
fix(eslint-plugin-query): handle nullish coalescing operator in exhaustive-deps rule (#8146)
* fix: handle nullish coalescing operator in exhaustive-deps rule Ensure that the exhaustive-deps rule correctly handles cases where the nullish coalescing operator (??) is used in query functions. Example test case: * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 495b086 commit c232a6f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@ ruleTester.run('exhaustive-deps', rule, {
413413
}
414414
`,
415415
},
416+
{
417+
name: 'should not fail when queryFn uses nullish coalescing operator',
418+
code: normalizeIndent`
419+
useQuery({
420+
queryKey: ["foo", options],
421+
queryFn: () => options?.params ?? options
422+
});
423+
`,
424+
},
416425
],
417426
invalid: [
418427
{

packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const rule = createRule({
115115
!ref.isTypeReference &&
116116
!ASTUtils.isAncestorIsCallee(ref.identifier) &&
117117
!existingKeys.some((existingKey) => existingKey === text) &&
118-
!existingKeys.includes(text.split('.')[0] ?? '')
118+
!existingKeys.includes(text.split(/[?.]/)[0] ?? '')
119119
)
120120
})
121121
.map(({ ref, text }) => ({

0 commit comments

Comments
 (0)