ESLint Plugin Query
This ESLint plugin is tailored for projects using @openapi-qraft/react
. It helps enforce best practices around the generated hooks (e.g.
qraft.service.operation.useQuery()
, qraft.useInfiniteQuery()
), and prevents common mistakes that lead to unnecessary re-renders or type inference issues.
Installationโ
The plugin is a separate package that you need to install:
- npm
- yarn
- pnpm
npm i -D @openapi-qraft/eslint-plugin-query
yarn add --dev @openapi-qraft/eslint-plugin-query
pnpm add -D @openapi-qraft/eslint-plugin-query
Flat Config (eslint.config.js
)โ
Recommended setupโ
To enable all the recommended rules for our plugin, add the following config:
import pluginQraftQuery from '@openapi-qraft/eslint-plugin-query'
export default [
...pluginQraftQuery.configs['flat/recommended'],
// Any other config...
]
Legacy Config (.eslintrc
)โ
Recommended setupโ
To enable all the recommended rules for our plugin, add plugin:@openapi-qraft/query/recommended
in extends:
{
"extends": [
"plugin:@openapi-qraft/query/recommended"
]
}
Custom setupโ
Alternatively, configure only the rules you want to use.
Flat config (eslint.config.js
)โ
import pluginQraftQuery from '@openapi-qraft/eslint-plugin-query';
export default [
{
plugins: {
'@openapi-qraft/query': pluginQraftQuery,
},
rules: {
// enable only the rules you need
'@openapi-qraft/query/no-rest-destructuring': 'warn',
'@openapi-qraft/query/no-unstable-deps': 'error',
},
},
// Any other config...
];
Legacy config (.eslintrc
)โ
{
"plugins": [
"@openapi-qraft/query"
],
"rules": {
"@openapi-qraft/query/no-rest-destructuring": "warn",
"@openapi-qraft/query/no-unstable-deps": "error"
}
}
Client name detectionโ
Some rules in this plugin detect Qraft-generated hooks only when they are called as methods on your client instance (e.g. qraft.service.operation.useQuery()
).
To support custom client names, each rule accepts an optional clientNamePattern
(string or regex literal) option. You can pass a regex literal like
/customClientName/i
. By default, it matches the case-insensitive regex /qraft|api/i
.
Optional: clientNamePatternโ
Flat config (eslint.config.js
)โ
import pluginQraftQuery from '@openapi-qraft/eslint-plugin-query'
export default [
{
plugins: { '@openapi-qraft/query': pluginQraftQuery },
rules: {
'@openapi-qraft/query/no-rest-destructuring': [
'warn',
{ clientNamePattern: '/myQraftClient/i' },
],
'@openapi-qraft/query/no-unstable-deps': [
'error',
{ clientNamePattern: '/myQraftClient/i' },
],
},
},
]
Legacy config (.eslintrc
)โ
{
"plugins": [
"@openapi-qraft/query"
],
"rules": {
"@openapi-qraft/query/no-rest-destructuring": [
"warn",
{
"clientNamePattern": "/myQraftClient/i"
}
],
"@openapi-qraft/query/no-unstable-deps": [
"error",
{
"clientNamePattern": "/myQraftClient/i"
}
]
}
}