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

eslint-plugin-query.md

86 lines1.8 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
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...
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...
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
65 "extends": ["plugin:@tanstack/eslint-plugin-query/recommended"]
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
75 "plugins": ["@tanstack/query"],
76 "rules": {
77 "@tanstack/query/exhaustive-deps": "error"
78 }
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)