MCPcopy Create free account
hub / github.com/TanStack/query / getFunctionAncestor

Function getFunctionAncestor

packages/eslint-plugin-query/src/utils/ast-utils.ts:160–189  ·  view source on GitHub ↗
(
    sourceCode: Readonly<TSESLint.SourceCode>,
    node: TSESTree.Node,
  )

Source from the content-addressed store, hash-verified

158 )
159 },
160 getFunctionAncestor(
161 sourceCode: Readonly<TSESLint.SourceCode>,
162 node: TSESTree.Node,
163 ) {
164 for (const ancestor of sourceCode.getAncestors(node)) {
165 if (
166 ASTUtils.isNodeOfOneOf(ancestor, [
167 AST_NODE_TYPES.FunctionDeclaration,
168 AST_NODE_TYPES.FunctionExpression,
169 AST_NODE_TYPES.ArrowFunctionExpression,
170 ])
171 ) {
172 return ancestor
173 }
174
175 if (
176 ancestor.parent?.type === AST_NODE_TYPES.VariableDeclarator &&
177 ancestor.parent.id.type === AST_NODE_TYPES.Identifier &&
178 ASTUtils.isNodeOfOneOf(ancestor, [
179 AST_NODE_TYPES.FunctionDeclaration,
180 AST_NODE_TYPES.FunctionExpression,
181 AST_NODE_TYPES.ArrowFunctionExpression,
182 ])
183 ) {
184 return ancestor
185 }
186 }
187
188 return undefined
189 },
190 getReferencedExpressionByIdentifier(params: {
191 node: TSESTree.Node
192 context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected