Skip to content

Commit

Permalink
fix(eslint-plugin-query): get scope from sourceCode (#7760)
Browse files Browse the repository at this point in the history
in eslint v9, context.getScope() doesn't exist anymore. see: https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
  • Loading branch information
TkDodo committed Jul 18, 2024
1 parent ae8738a commit e61edd2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/eslint-plugin-query/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,16 @@ export const ASTUtils = {
}) {
const { node, context } = params

const resolvedNode = context
.getScope()
.references.find((ref) => ref.identifier === node)?.resolved?.defs[0]
?.node
// we need the fallbacks for backwards compat with eslint < 8.37.0
// eslint-disable-next-line ts/no-unnecessary-condition
const sourceCode = context.sourceCode ?? context.getSourceCode()
// eslint-disable-next-line ts/no-unnecessary-condition
const scope = context.sourceCode.getScope(node)
? sourceCode.getScope(node)
: context.getScope()

const resolvedNode = scope.references.find((ref) => ref.identifier === node)
?.resolved?.defs[0]?.node

if (resolvedNode?.type !== AST_NODE_TYPES.VariableDeclarator) {
return null
Expand Down

0 comments on commit e61edd2

Please sign in to comment.