Skip to content

Commit

Permalink
fix(eslint-plugin-query): handle nullish coalescing operator in exhau…
Browse files Browse the repository at this point in the history
…stive-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>
  • Loading branch information
Newbie012 and autofix-ci[bot] authored Oct 8, 2024
1 parent 495b086 commit c232a6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ ruleTester.run('exhaustive-deps', rule, {
}
`,
},
{
name: 'should not fail when queryFn uses nullish coalescing operator',
code: normalizeIndent`
useQuery({
queryKey: ["foo", options],
queryFn: () => options?.params ?? options
});
`,
},
],
invalid: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const rule = createRule({
!ref.isTypeReference &&
!ASTUtils.isAncestorIsCallee(ref.identifier) &&
!existingKeys.some((existingKey) => existingKey === text) &&
!existingKeys.includes(text.split('.')[0] ?? '')
!existingKeys.includes(text.split(/[?.]/)[0] ?? '')
)
})
.map(({ ref, text }) => ({
Expand Down

0 comments on commit c232a6f

Please sign in to comment.