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

eslint-plugin-query.md

102 lines2.1 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### 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...
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
77 "extends": ["plugin:@tanstack/query/recommended"]
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
87 "plugins": ["@tanstack/query"],
88 "rules": {
89 "@tanstack/query/exhaustive-deps": "error"
90 }
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)