-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eslint-plugin): ignore queryClient from exhaustive-check (#5291)
* fix(eslint-plugin): ignore queryClient * Update packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.test.ts --------- Co-authored-by: Dominik Dorfmeister <[email protected]>
- Loading branch information
Showing
3 changed files
with
68 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/eslint-plugin-query/src/rules/exhaustive-deps/exhaustive-deps.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils' | ||
import { AST_NODE_TYPES } from '@typescript-eslint/utils' | ||
import { ASTUtils } from '../../utils/ast-utils' | ||
|
||
export const ExhaustiveDepsUtils = { | ||
isRelevantReference(params: { | ||
context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>> | ||
reference: TSESLint.Scope.Reference | ||
scopeManager: TSESLint.Scope.ScopeManager | ||
}) { | ||
const { reference, scopeManager, context } = params | ||
const component = ASTUtils.getReactComponentOrHookAncestor(context) | ||
|
||
if ( | ||
component !== undefined && | ||
!ASTUtils.isDeclaredInNode({ | ||
scopeManager, | ||
reference, | ||
functionNode: component, | ||
}) | ||
) { | ||
return false | ||
} | ||
|
||
return ( | ||
reference.identifier.name !== 'undefined' && | ||
reference.identifier.parent?.type !== AST_NODE_TYPES.NewExpression && | ||
!ExhaustiveDepsUtils.isQueryClientReference(reference) | ||
) | ||
}, | ||
isQueryClientReference(reference: TSESLint.Scope.Reference) { | ||
const declarator = reference.resolved?.defs[0]?.node | ||
|
||
return ( | ||
declarator?.type === AST_NODE_TYPES.VariableDeclarator && | ||
declarator.init?.type === AST_NODE_TYPES.CallExpression && | ||
declarator.init.callee.type === AST_NODE_TYPES.Identifier && | ||
declarator.init.callee.name === 'useQueryClient' | ||
) | ||
}, | ||
} |