Skip to content

[eslint-plugin-query] exhaustive-deps rule ignores top-level <script> variables in .svelte files #12552

Open

Description

@BastiDood

Describe the bug

In a .svelte component, exhaustive-deps fails to flag missing variables in a queryKey.

<script>
  import { createQuery } from '@tanstack/svelte-query';

  let id = $state(1);

  // `id` is missing from the `queryKey`, yet no errors flagged!
  const todo = createQuery(() => ({
    queryKey: ['todo'],
    queryFn: () => fetchTodo(id),
  }));
</script>

However, if you put createQuery inside a function, suddenly it works again.

function createTodo(id) {
  return createQuery(() => ({
    queryKey: ['todo'],
    queryFn: () => fetchTodo(id),
  }));
}

I think this is because the rule currently treats the enclosing function as the component (a la React). In the Svelte adapter, that function is always the createQuery accessor, which declares nothing in the function body, so every $props/$state/$derived in the actual top level gets ignored.

Your minimal, reproducible example

https://stackblitz.com/edit/stackblitz-starters-jiae8x7n?file=src%2Froutes%2F%2Bpage.svelte&view=editor

Steps to reproduce

  1. Run npm install.
  2. Run npm run lint.
  3. Observe that the @tanstack/query/exhaustive-deps rule only fails when createQuery is nested inside a function.

Expected behavior

The lint rule should've flagged at the top-level createQuery.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

N/A because the issue points to a non-platform-dependent parser/traversal bug.

Tanstack Query adapter

svelte-query

TanStack Query version

6.4.1

TypeScript version

No response

Additional context

Note that the .vue fallback added in #10011 (for #9962) doesn't apply to .svelte files. Some logic can be shared/adapted, though! That would be great place to start.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions