-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathprefer-query-options.utils.ts
More file actions
23 lines (19 loc) · 876 Bytes
/
prefer-query-options.utils.ts
File metadata and controls
23 lines (19 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import type { TSESTree } from '@typescript-eslint/utils'
const MAIN_QUERY_PROPERTIES = ['queryKey', 'queryFn']
/**
* @returns true if the node is an object that has main query options (ie queryKey or queryFn).
* This is used for detecting inline query options in hooks and functions
*/
export function detectQueryOptionsInObject(queryNode: TSESTree.Node): boolean {
// skip if it's not an object
if (queryNode.type !== AST_NODE_TYPES.ObjectExpression) return false
// check if any of the properties is queryKey or queryFn
const hasMainQueryProperties = queryNode.properties.find(
(property) =>
property.type === AST_NODE_TYPES.Property &&
property.key.type === AST_NODE_TYPES.Identifier &&
MAIN_QUERY_PROPERTIES.includes(property.key.name),
)
return !!hasMainQueryProperties
}