Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

eslint-plugin-query.md

126 lines2.6 KB

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...
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...
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...
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
90 "extends": ["plugin:@tanstack/query/recommended"]
92```
93​
94### Recommended strict setup
95​
96The `recommendedStrict` config extends `recommended` with additional opinionated rules:
97​
98```json
100 "extends": ["plugin:@tanstack/query/recommendedStrict"]
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
110 "plugins": ["@tanstack/query"],
111 "rules": {
112 "@tanstack/query/exhaustive-deps": "error"
113 }
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)