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
13npm i -D @tanstack/eslint-plugin-query
14```
15β
16or
17β
18```bash
19pnpm add -D @tanstack/eslint-plugin-query
20```
21β
22or
23β
24```bash
25yarn add -D @tanstack/eslint-plugin-query
26```
27β
28or
29β
30```bash
31bun add -D @tanstack/eslint-plugin-query
32```
33β
34## Flat Config (`eslint.config.js`)
35β
36### Recommended setup
37β
38To enable all of the recommended rules for our plugin, add the following config:
39β
40```js
41import pluginQuery from '@tanstack/eslint-plugin-query'
42β
43export default [
44 ...pluginQuery.configs['flat/recommended'],
45 // Any other config...
46]
47```
48β
49### Custom setup
50β
51Alternatively, you can load the plugin and configure only the rules you want to use:
52β
53```js
54import pluginQuery from '@tanstack/eslint-plugin-query'
55β
56export default [
57 {
58 plugins: {
59 '@tanstack/query': pluginQuery,
60 },
61 rules: {
62 '@tanstack/query/exhaustive-deps': 'error',
63 },
64 },
65 // Any other config...
66]
67```
68β
69## Legacy Config (`.eslintrc`)
70β
71### Recommended setup
72β
73To enable all of the recommended rules for our plugin, add `plugin:@tanstack/query/recommended` in extends:
74β
75```json
76{
77 "extends": ["plugin:@tanstack/query/recommended"]
78}
79```
80β
81### Custom setup
82β
83Alternatively, add `@tanstack/query` to the plugins section, and configure the rules you want to use:
84β
85```json
86{
87 "plugins": ["@tanstack/query"],
88 "rules": {
89 "@tanstack/query/exhaustive-deps": "error"
90 }
91}
92```
93β
94## Rules
95β
96- [@tanstack/query/exhaustive-deps](../exhaustive-deps.md)
97- [@tanstack/query/no-rest-destructuring](../no-rest-destructuring.md)
98- [@tanstack/query/stable-query-client](../stable-query-client.md)
99- [@tanstack/query/no-unstable-deps](../no-unstable-deps.md)
100- [@tanstack/query/infinite-query-property-order](../infinite-query-property-order.md)
101- [@tanstack/query/no-void-query-fn](../no-void-query-fn.md)
102- [@tanstack/query/mutation-property-order](../mutation-property-order.md)