Skip to content

Commit b9a478d

Browse files
authored
fix(eslint-plugin): avoid imports from typescript (#9759)
* fix(eslint-plugin): avoid imports from typescript * add changeset * fix
1 parent 36ece87 commit b9a478d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.changeset/shy-wasps-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/eslint-plugin-query': patch
3+
---
4+
5+
avoid typescript import in no-void-query-fn rule

packages/eslint-plugin-query/src/rules/no-void-query-fn/no-void-query-fn.rule.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { ESLintUtils } from '@typescript-eslint/utils'
2-
import ts from 'typescript'
32
import { ASTUtils } from '../../utils/ast-utils'
43
import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
54
import { getDocsUrl } from '../../utils/get-docs-url'
5+
import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils'
66
import type { ExtraRuleDocs } from '../../types'
77

8+
const TypeFlags = {
9+
Void: 16384,
10+
Undefined: 32768,
11+
} as const
12+
813
export const name = 'no-void-query-fn'
914

1015
const createRule = ESLintUtils.RuleCreator<ExtraRuleDocs>(getDocsUrl)
@@ -69,7 +74,11 @@ export const rule = createRule({
6974
}),
7075
})
7176

72-
function isIllegalReturn(checker: ts.TypeChecker, type: ts.Type): boolean {
77+
type Program = ParserServicesWithTypeInformation['program']
78+
type TypeChecker = ReturnType<Program['getTypeChecker']>
79+
type Type = ReturnType<TypeChecker['getTypeAtLocation']>
80+
81+
function isIllegalReturn(checker: TypeChecker, type: Type): boolean {
7382
const awaited = checker.getAwaitedType(type)
7483

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

81-
return awaited.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined)
82-
? true
83-
: false
90+
return awaited.flags & (TypeFlags.Void | TypeFlags.Undefined) ? true : false
8491
}

0 commit comments

Comments
 (0)