Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/shy-wasps-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/eslint-plugin-query': patch
---

avoid typescript import in no-void-query-fn rule
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { ESLintUtils } from '@typescript-eslint/utils'
import ts from 'typescript'
import { ASTUtils } from '../../utils/ast-utils'
import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
import { getDocsUrl } from '../../utils/get-docs-url'
import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils'
import type { ExtraRuleDocs } from '../../types'

const TypeFlags = {
Void: 16384,
Undefined: 32768,
} as const

export const name = 'no-void-query-fn'

const createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)
Expand Down Expand Up @@ -69,7 +74,11 @@ export const rule = createRule({
}),
})

function isIllegalReturn(checker: ts.TypeChecker, type: ts.Type): boolean {
type Program = ParserServicesWithTypeInformation['program']
type TypeChecker = ReturnType<Program['getTypeChecker']>
type Type = ReturnType<TypeChecker['getTypeAtLocation']>

function isIllegalReturn(checker: TypeChecker, type: Type): boolean {
const awaited = checker.getAwaitedType(type)

if (!awaited) return false
Expand All @@ -78,7 +87,5 @@ function isIllegalReturn(checker: ts.TypeChecker, type: ts.Type): boolean {
return awaited.types.some((t) => isIllegalReturn(checker, t))
}

return awaited.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined)
? true
: false
return awaited.flags & (TypeFlags.Void | TypeFlags.Undefined) ? true : false
}
Loading