Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const title = 'No React Query usage'

export function Example() {
const greeting = title.toUpperCase()

return <div>{greeting}</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const title = 'No React Query usage'

export function Example() {
const greeting = title.toUpperCase()

return <div>{greeting}</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ defineTest(
defineTest(__dirname, 'key-transformation.cjs', null, 'type-arguments', {
parser: 'tsx',
})

defineTest(__dirname, 'key-transformation.cjs', null, 'no-react-query-import', {
parser: 'tsx',
})
12 changes: 11 additions & 1 deletion packages/query-codemods/src/v4/key-transformation.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,17 @@ module.exports = (file, api) => {
const jscodeshift = api.jscodeshift
const root = jscodeshift(file.source)

// TODO: Execute the transformers only when it contains a `react-query` import!
const hasReactQueryImport = root
.find(jscodeshift.ImportDeclaration, {
source: {
value: 'react-query',
},
})
.paths().length

if (!hasReactQueryImport) {
return file.source
}

const utils = createUtilsObject({ root, jscodeshift })
const filePath = file.path
Expand Down