@noctcore/eslint-plugin-query
A bad fit for tRPC's classic utils.x.invalidate() integration, where the first rule has nothing to check.
TanStack Query and tRPC cache correctness: invalidations that reach infinite queries, mutation callbacks that survive a remount, handled mutation errors.
What it solves
Section titled “What it solves”The client cache fails in ways that pass type checks and unit tests that mock the client. An invalidation keyed with tRPC’s input-less queryKey() stops reaching a list the day it moves to useInfiniteQuery. A mutate(vars, { onSuccess }) fired from an effect loses its callback when StrictMode or a route change detaches the observer, and the screen waits forever. A mutation with nothing listening for its error fails without anyone noticing.
What it will yell at you about
Section titled “What it will yell at you about”It will yell at you about tRPC invalidations through an input-less queryKey() (with an autofix to pathKey()) and per-call mutation callbacks inside useEffect, both on in recommended. Mutations with no error handling anywhere is opt-in, because a global MutationCache({ onError }) handles errors where the rule cannot see. Inline query keys (queryKey: ['user', id]) is opt-in too, a convention for codebases that keep keys in a constant or key factory. An exact-key setQueryData(PREFIX, ...) or getQueryData(PREFIX) where the hooks key entries as [...PREFIX, id] is opt-in as well, because the rule reads one file at a time. A queryFn that catches its error and returns a fallback is opt-in too, because returning null for an optional resource is a legitimate contract. It is a bad fit for tRPC’s classic utils.x.invalidate() integration, where the first rule has nothing to check.
Install and configure
Section titled “Install and configure”npm install --save-dev @noctcore/eslint-plugin-query @typescript-eslint/parser# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-query @typescript-eslint/parserThe recommended preset enables 2 of 6 rules. The rules board below builds the flat config: start from a preset, switch single rules between error and off, and copy the result.
Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first
read is trpc-invalidate-with-path-key.
--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.
useMutation, not as per-call mutate() options, which a detached observer never delivers.onError on the hook, onError or a catch at the call, or a read of its error state.setQueryData(PREFIX, ...) and getQueryData(PREFIX) when the file builds its query keys as [...PREFIX, id]: the exact-key call misses every entry, and setQueriesData / getQueriesData match the prefix.queryFn that catches its error and returns a fallback value, which turns a failed request into cached data the query reports as a success.pathKey() when a tRPC procedure is invalidated, refetched, cancelled, removed or reset without an input. A bare queryKey() misses infinite queries.