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### Recommended strict setup
50β
51The `flat/recommended-strict` config extends `flat/recommended` with additional opinionated rules that enforce best practices more aggressively.
52β
53```js
54import pluginQuery from '@tanstack/eslint-plugin-query'
55β
56export default [
57 ...pluginQuery.configs['flat/recommended-strict'],
58 // Any other config...
59]
60```
61β
62### Custom setup
63β
64Alternatively, you can load the plugin and configure only the rules you want to use:
65β
66```js
67import pluginQuery from '@tanstack/eslint-plugin-query'
68β
69export default [
70 {
71 plugins: {
72 '@tanstack/query': pluginQuery,
73 },
74 rules: {
75 '@tanstack/query/exhaustive-deps': 'error',
76 },
77 },
78 // Any other config...
79]
80```
81β
82## Legacy Config (`.eslintrc`)
83β
84### Recommended setup
85β
86To enable all of the recommended rules for our plugin, add `plugin:@tanstack/query/recommended` in extends:
87β
88```json
89{
90 "extends": ["plugin:@tanstack/query/recommended"]
91}
92```
93β
94### Recommended strict setup
95β
96The `recommendedStrict` config extends `recommended` with additional opinionated rules:
97β
98```json
99{
100 "extends": ["plugin:@tanstack/query/recommendedStrict"]
101}
102```
103β
104### Custom setup
105β
106Alternatively, add `@tanstack/query` to the plugins section, and configure the rules you want to use:
107β
108```json
109{
110 "plugins": ["@tanstack/query"],
111 "rules": {
112 "@tanstack/query/exhaustive-deps": "error"
113 }
114}
115```
116β
117## Rules
118β
119- [@tanstack/query/exhaustive-deps](./exhaustive-deps.md)
120- [@tanstack/query/no-rest-destructuring](./no-rest-destructuring.md)
121- [@tanstack/query/stable-query-client](./stable-query-client.md)
122- [@tanstack/query/no-unstable-deps](./no-unstable-deps.md)
123- [@tanstack/query/infinite-query-property-order](./infinite-query-property-order.md)
124- [@tanstack/query/no-void-query-fn](./no-void-query-fn.md)
125- [@tanstack/query/mutation-property-order](./mutation-property-order.md)
126- [@tanstack/query/prefer-query-options](./prefer-query-options.md)