-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(eslint-plugin): add allowlist option to exhaustive-deps rule #10295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Newbie012
wants to merge
5
commits into
main
Choose a base branch
from
feat-eslint-exhaustive-deps-allowlist
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1bb212
feat(eslint-plugin): add allowlist option to exhaustive-deps rule
Newbie012 4506302
fix
Newbie012 7b0f821
ci: apply automated fixes
autofix-ci[bot] b0ef990
increase coverage
Newbie012 98868ec
Merge branch 'feat-eslint-exhaustive-deps-allowlist' of github.com:Taβ¦
Newbie012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@tanstack/eslint-plugin-query': minor | ||
| --- | ||
|
|
||
| BREAKING (eslint-plugin): The `exhaustive-deps` rule now reports member expression dependencies more granularly for call expressions (e.g. `a.b.foo()` suggests `a.b`), which may cause existing code that previously passed the rule to now report missing dependencies. To accommodate stable variables and types, the rule now accepts an `allowlist` option with `variables` and `types` arrays to exclude specific dependencies from enforcement. | ||
This file contains hidden or 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 hidden or 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,21 @@ | ||
| import pluginQuery from '@tanstack/eslint-plugin-query' | ||
| import tseslint from 'typescript-eslint' | ||
|
|
||
| export default [ | ||
| ...tseslint.configs.recommended, | ||
| ...pluginQuery.configs['flat/recommended'], | ||
| { | ||
| files: ['src/**/*.ts', 'src/**/*.tsx'], | ||
| rules: { | ||
| '@tanstack/query/exhaustive-deps': [ | ||
| 'error', | ||
| { | ||
| allowlist: { | ||
| variables: ['api'], | ||
| types: ['AnalyticsClient'], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ] |
This file contains hidden or 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,27 @@ | ||
| { | ||
| "name": "@tanstack/query-example-eslint-plugin-demo", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "test:eslint": "eslint ./src" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/react-query": "^5.91.0", | ||
| "react": "^19.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@tanstack/eslint-plugin-query": "^5.91.5", | ||
| "eslint": "^9.39.0", | ||
| "typescript": "5.8.3", | ||
| "typescript-eslint": "^8.48.0" | ||
Newbie012 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| "nx": { | ||
| "targets": { | ||
| "test:eslint": { | ||
| "dependsOn": [ | ||
| "^build" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,55 @@ | ||
| import { queryOptions } from '@tanstack/react-query' | ||
|
|
||
| export function todosOptions(userId: string) { | ||
| const api = useApiClient() | ||
| return queryOptions({ | ||
| // β passes: 'api' is in allowlist.variables | ||
| queryKey: ['todos', userId], | ||
| queryFn: () => api.fetchTodos(userId), | ||
| }) | ||
| } | ||
|
|
||
| export function todosByApiOptions(userId: string) { | ||
| const todoApi = useApiClient() | ||
| // β fails: 'api' is in allowlist.variables, but this variable is named 'todoApi' | ||
| // eslint-disable-next-line @tanstack/query/exhaustive-deps -- The following dependencies are missing in your queryKey: todoApi | ||
| return queryOptions({ | ||
| queryKey: ['todos', userId], | ||
| queryFn: () => todoApi.fetchTodos(userId), | ||
| }) | ||
| } | ||
|
|
||
| export function todosWithTrackingOptions( | ||
| tracker: AnalyticsClient, | ||
| userId: string, | ||
| ) { | ||
| return queryOptions({ | ||
| // β passes: AnalyticsClient is in allowlist.types | ||
| queryKey: ['todos', userId], | ||
| queryFn: async () => { | ||
| tracker.track('todos') | ||
| return fetch(`/api/todos?userId=${userId}`).then((r) => r.json()) | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| export function todosWithClientOptions(client: ApiClient, userId: string) { | ||
| // β fails: AnalyticsClient is in allowlist.types, but this param is typed as ApiClient | ||
| // eslint-disable-next-line @tanstack/query/exhaustive-deps -- The following dependencies are missing in your queryKey: client | ||
| return queryOptions({ | ||
| queryKey: ['todos', userId], | ||
| queryFn: () => client.fetchTodos(userId), | ||
| }) | ||
| } | ||
|
|
||
| interface ApiClient { | ||
| fetchTodos: (userId: string) => Promise<Array<{ id: string }>> | ||
| } | ||
|
|
||
| interface AnalyticsClient { | ||
| track: (event: string) => Promise<void> | ||
| } | ||
|
|
||
| function useApiClient(): ApiClient { | ||
| throw new Error('not implemented') | ||
| } |
This file contains hidden or 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,14 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "lib": ["ES2020", "DOM"], | ||
| "module": "ESNext", | ||
| "skipLibCheck": true, | ||
| "moduleResolution": "Bundler", | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
| "strict": true | ||
| }, | ||
| "include": ["src", "eslint.config.js"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.