Open History to see the last commit
1---
2id: eslint-plugin-query
3title: ESLint Plugin Query
4---
5β
6TanStack Query comes with its own ESLint plugin. This plugin is used to enforce best practices and to help you avoid common mistakes.
7β
8## Installation
9β
10The plugin is a separate package that you need to install:
11β
12```bash
13$ npm i -D @tanstack/eslint-plugin-query
14# or
15$ pnpm add -D @tanstack/eslint-plugin-query
16# or
17$ yarn add -D @tanstack/eslint-plugin-query
18# or
19$ bun add -D @tanstack/eslint-plugin-query
20```
21β
22## Flat Config (`eslint.config.js`)
23β
24### Recommended setup
25β
26To enable all of the recommended rules for our plugin, add the following config:
27β
28```js
29import pluginQuery from '@tanstack/eslint-plugin-query'
30β
31export default [
32 ...pluginQuery.configs['flat/recommended'],
33 // Any other config...
34]
35```
36β
37### Custom setup
38β
39Alternatively, you can load the plugin and configure only the rules you want to use:
40β
41```js
42import pluginQuery from '@tanstack/eslint-plugin-query'
43β
44export default [
45 {
46 plugins: {
47 '@tanstack/query': pluginQuery,
48 },
49 rules: {
50 '@tanstack/query/exhaustive-deps': 'error',
51 },
52 },
53 // Any other config...
54]
55```
56β
57## Legacy Config (`.eslintrc`)
58β
59### Recommended setup
60β
61To enable all of the recommended rules for our plugin, add `plugin:@tanstack/eslint-plugin-query/recommended` in extends:
62β
63```json
64{
65 "extends": ["plugin:@tanstack/eslint-plugin-query/recommended"]
66}
67```
68β
69### Custom setup
70β
71Alternatively, add `@tanstack/eslint-plugin-query` to the plugins section, and configure the rules you want to use:
72β
73```json
74{
75 "plugins": ["@tanstack/query"],
76 "rules": {
77 "@tanstack/query/exhaustive-deps": "error"
78 }
79}
80```
81β
82## Rules
83β
84- [@tanstack/query/exhaustive-deps](../exhaustive-deps)
85- [@tanstack/query/no-rest-destructuring](../no-rest-destructuring)
86- [@tanstack/query/stable-query-client](../stable-query-client)