-
-
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(codemod): extend the remove overloads codemod logic (#6268)
* fix(codemod): extend codemod logic to transform usages when the second parameter is a function in the scope * fix(codemod): handle the case when the second argument is a function definition * chore(codemod): fix the `eslint` issue in the newly added example --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
- Loading branch information
1 parent
6b79e10
commit fe87fc1
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/codemods/src/v5/remove-overloads/__testfixtures__/bug-reports.input.tsx
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,27 @@ | ||
// From: https://github.com/TanStack/query/issues/6204 | ||
export function useDetails({ groupId }: { groupId?: string }): any { | ||
const cacheKey = ["details", groupId]; | ||
const query = () => fetch(`/group/${groupId}`); | ||
const queryObject = useQuery(cacheKey, query, { | ||
enabled: !!groupId, | ||
}); | ||
return queryObject; | ||
} | ||
|
||
// Based on: https://github.com/TanStack/query/issues/6204 | ||
export function useDetailsContainsIdentifierAsThirdArgument({ groupId }: { groupId?: string }): any { | ||
const cacheKey = ["details", groupId]; | ||
const query = () => fetch(`/group/${groupId}`); | ||
const opts = { enabled: !!groupId } | ||
const queryObject = useQuery(cacheKey, query, opts); | ||
return queryObject; | ||
} | ||
|
||
// From: https://twitter.com/samcook_/status/1715063150184132902 | ||
export function useWhatever({ thing }: { thing: string }) { | ||
return useQuery( | ||
['some-string', someVar], | ||
async () => 'foo', | ||
{ enabled: Boolean(thing) }, | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/codemods/src/v5/remove-overloads/__testfixtures__/bug-reports.output.tsx
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,34 @@ | ||
// From: https://github.com/TanStack/query/issues/6204 | ||
export function useDetails({ groupId }: { groupId?: string }): any { | ||
const cacheKey = ["details", groupId]; | ||
const query = () => fetch(`/group/${groupId}`); | ||
const queryObject = useQuery({ | ||
queryKey: cacheKey, | ||
queryFn: query, | ||
enabled: !!groupId | ||
}); | ||
return queryObject; | ||
} | ||
|
||
// Based on: https://github.com/TanStack/query/issues/6204 | ||
export function useDetailsContainsIdentifierAsThirdArgument({ groupId }: { groupId?: string }): any { | ||
const cacheKey = ["details", groupId]; | ||
const query = () => fetch(`/group/${groupId}`); | ||
const opts = { enabled: !!groupId } | ||
const queryObject = useQuery({ | ||
queryKey: cacheKey, | ||
queryFn: query, | ||
...opts | ||
}); | ||
return queryObject; | ||
} | ||
|
||
// From: https://twitter.com/samcook_/status/1715063150184132902 | ||
export function useWhatever({ thing }: { thing: string }) { | ||
return useQuery({ | ||
queryKey: ['some-string', someVar], | ||
queryFn: async () => 'foo', | ||
enabled: Boolean(thing) | ||
}); | ||
} | ||
|
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