File size: 2,040 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
---
id: eslint-plugin-query
title: ESLint Plugin Query
---
TanStack Query comes with its own ESLint plugin. This plugin is used to enforce best practices and to help you avoid common mistakes.
## Installation
The plugin is a separate package that you need to install:
```bash
npm i -D @tanstack/eslint-plugin-query
```
or
```bash
pnpm add -D @tanstack/eslint-plugin-query
```
or
```bash
yarn add -D @tanstack/eslint-plugin-query
```
or
```bash
bun add -D @tanstack/eslint-plugin-query
```
## Flat Config (`eslint.config.js`)
### Recommended setup
To enable all of the recommended rules for our plugin, add the following config:
```js
import pluginQuery from '@tanstack/eslint-plugin-query'
export default [
...pluginQuery.configs['flat/recommended'],
// Any other config...
]
```
### Custom setup
Alternatively, you can load the plugin and configure only the rules you want to use:
```js
import pluginQuery from '@tanstack/eslint-plugin-query'
export default [
{
plugins: {
'@tanstack/query': pluginQuery,
},
rules: {
'@tanstack/query/exhaustive-deps': 'error',
},
},
// Any other config...
]
```
## Legacy Config (`.eslintrc`)
### Recommended setup
To enable all of the recommended rules for our plugin, add `plugin:@tanstack/query/recommended` in extends:
```json
{
"extends": ["plugin:@tanstack/query/recommended"]
}
```
### Custom setup
Alternatively, add `@tanstack/query` to the plugins section, and configure the rules you want to use:
```json
{
"plugins": ["@tanstack/query"],
"rules": {
"@tanstack/query/exhaustive-deps": "error"
}
}
```
## Rules
- [@tanstack/query/exhaustive-deps](../exhaustive-deps.md)
- [@tanstack/query/no-rest-destructuring](../no-rest-destructuring.md)
- [@tanstack/query/stable-query-client](../stable-query-client.md)
- [@tanstack/query/no-unstable-deps](../no-unstable-deps.md)
- [@tanstack/query/infinite-query-property-order](../infinite-query-property-order.md)
- [@tanstack/query/no-void-query-fn](../no-void-query-fn.md)
|