@@ -5,6 +5,7 @@ import { FindVariableContext } from '../utils/ast-utils.js';
5
5
import { findVariable } from '../utils/ast-utils.js' ;
6
6
import type { RuleContext } from '../types.js' ;
7
7
import type { AST } from 'svelte-eslint-parser' ;
8
+ import { type TSTools , getTypeScriptTools } from 'src/utils/ts-utils/index.js' ;
8
9
9
10
export default createRule ( 'no-navigation-without-resolve' , {
10
11
meta : {
@@ -48,6 +49,8 @@ export default createRule('no-navigation-without-resolve', {
48
49
]
49
50
} ,
50
51
create ( context ) {
52
+ const tsTools = getTypeScriptTools ( context ) ;
53
+
51
54
let resolveReferences : Set < TSESTree . Identifier > = new Set < TSESTree . Identifier > ( ) ;
52
55
return {
53
56
Program ( ) {
@@ -60,7 +63,7 @@ export default createRule('no-navigation-without-resolve', {
60
63
} = extractFunctionCallReferences ( referenceTracker ) ;
61
64
if ( context . options [ 0 ] ?. ignoreGoto !== true ) {
62
65
for ( const gotoCall of gotoCalls ) {
63
- checkGotoCall ( context , gotoCall , resolveReferences ) ;
66
+ checkGotoCall ( context , gotoCall , resolveReferences , tsTools ) ;
64
67
}
65
68
}
66
69
if ( context . options [ 0 ] ?. ignorePushState !== true ) {
@@ -69,6 +72,7 @@ export default createRule('no-navigation-without-resolve', {
69
72
context ,
70
73
pushStateCall ,
71
74
resolveReferences ,
75
+ tsTools ,
72
76
'pushStateWithoutResolve'
73
77
) ;
74
78
}
@@ -79,6 +83,7 @@ export default createRule('no-navigation-without-resolve', {
79
83
context ,
80
84
replaceStateCall ,
81
85
resolveReferences ,
86
+ tsTools ,
82
87
'replaceStateWithoutResolve'
83
88
) ;
84
89
}
@@ -105,7 +110,8 @@ export default createRule('no-navigation-without-resolve', {
105
110
! isResolveCall (
106
111
new FindVariableContext ( context ) ,
107
112
node . value [ 0 ] . expression ,
108
- resolveReferences
113
+ resolveReferences ,
114
+ tsTools
109
115
) )
110
116
) {
111
117
context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
@@ -190,13 +196,14 @@ function extractFunctionCallReferences(referenceTracker: ReferenceTracker): {
190
196
function checkGotoCall (
191
197
context : RuleContext ,
192
198
call : TSESTree . CallExpression ,
193
- resolveReferences : Set < TSESTree . Identifier >
199
+ resolveReferences : Set < TSESTree . Identifier > ,
200
+ tsTools : TSTools | null
194
201
) : void {
195
202
if ( call . arguments . length < 1 ) {
196
203
return ;
197
204
}
198
205
const url = call . arguments [ 0 ] ;
199
- if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences ) ) {
206
+ if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools ) ) {
200
207
context . report ( { loc : url . loc , messageId : 'gotoWithoutResolve' } ) ;
201
208
}
202
209
}
@@ -205,6 +212,7 @@ function checkShallowNavigationCall(
205
212
context : RuleContext ,
206
213
call : TSESTree . CallExpression ,
207
214
resolveReferences : Set < TSESTree . Identifier > ,
215
+ tsTools : TSTools | null ,
208
216
messageId : string
209
217
) : void {
210
218
if ( call . arguments . length < 1 ) {
@@ -213,7 +221,7 @@ function checkShallowNavigationCall(
213
221
const url = call . arguments [ 0 ] ;
214
222
if (
215
223
! expressionIsEmpty ( url ) &&
216
- ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences )
224
+ ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools )
217
225
) {
218
226
context . report ( { loc : url . loc , messageId } ) ;
219
227
}
@@ -224,7 +232,8 @@ function checkShallowNavigationCall(
224
232
function isResolveCall (
225
233
ctx : FindVariableContext ,
226
234
node : TSESTree . CallExpressionArgument ,
227
- resolveReferences : Set < TSESTree . Identifier >
235
+ resolveReferences : Set < TSESTree . Identifier > ,
236
+ tsTools : TSTools | null
228
237
) : boolean {
229
238
if (
230
239
node . type === 'CallExpression' &&
@@ -235,9 +244,13 @@ function isResolveCall(
235
244
) {
236
245
return true ;
237
246
}
238
- if ( node . type !== 'Identifier' ) {
247
+ if ( node . type !== 'Identifier' || tsTools === null ) {
239
248
return false ;
240
249
}
250
+ const tsNode = tsTools . service . esTreeNodeToTSNodeMap . get ( node ) ;
251
+ console . log ( tsNode ) ;
252
+ console . log ( tsTools . service . program . getTypeChecker ( ) . getTypeAtLocation ( tsNode ) ) ;
253
+ /*
241
254
const variable = ctx.findVariable(node);
242
255
if (
243
256
variable === null ||
@@ -248,6 +261,7 @@ function isResolveCall(
248
261
return false;
249
262
}
250
263
return isResolveCall(ctx, variable.identifiers[0].parent.init, resolveReferences);
264
+ */
251
265
}
252
266
253
267
function expressionIsEmpty ( url : TSESTree . CallExpressionArgument ) : boolean {
0 commit comments