@@ -5,6 +5,7 @@ import { FindVariableContext } from '../utils/ast-utils.js';
55import { findVariable } from '../utils/ast-utils.js' ;
66import type { RuleContext } from '../types.js' ;
77import type { AST } from 'svelte-eslint-parser' ;
8+ import { type TSTools , getTypeScriptTools } from 'src/utils/ts-utils/index.js' ;
89
910export default createRule ( 'no-navigation-without-resolve' , {
1011 meta : {
@@ -48,6 +49,8 @@ export default createRule('no-navigation-without-resolve', {
4849 ]
4950 } ,
5051 create ( context ) {
52+ const tsTools = getTypeScriptTools ( context ) ;
53+
5154 let resolveReferences : Set < TSESTree . Identifier > = new Set < TSESTree . Identifier > ( ) ;
5255
5356 const ignoreGoto = context . options [ 0 ] ?. ignoreGoto ?? false ;
@@ -66,7 +69,7 @@ export default createRule('no-navigation-without-resolve', {
6669 } = extractFunctionCallReferences ( referenceTracker ) ;
6770 if ( ! ignoreGoto ) {
6871 for ( const gotoCall of gotoCalls ) {
69- checkGotoCall ( context , gotoCall , resolveReferences ) ;
72+ checkGotoCall ( context , gotoCall , resolveReferences , tsTools ) ;
7073 }
7174 }
7275 if ( ! ignorePushState ) {
@@ -75,6 +78,7 @@ export default createRule('no-navigation-without-resolve', {
7578 context ,
7679 pushStateCall ,
7780 resolveReferences ,
81+ tsTools ,
7882 'pushStateWithoutResolve'
7983 ) ;
8084 }
@@ -85,6 +89,7 @@ export default createRule('no-navigation-without-resolve', {
8589 context ,
8690 replaceStateCall ,
8791 resolveReferences ,
92+ tsTools ,
8893 'replaceStateWithoutResolve'
8994 ) ;
9095 }
@@ -133,7 +138,8 @@ export default createRule('no-navigation-without-resolve', {
133138 ! isResolveCall (
134139 new FindVariableContext ( context ) ,
135140 node . value [ 0 ] . expression ,
136- resolveReferences
141+ resolveReferences ,
142+ tsTools
137143 ) )
138144 ) {
139145 context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
@@ -221,13 +227,14 @@ function extractFunctionCallReferences(referenceTracker: ReferenceTracker): {
221227function checkGotoCall (
222228 context : RuleContext ,
223229 call : TSESTree . CallExpression ,
224- resolveReferences : Set < TSESTree . Identifier >
230+ resolveReferences : Set < TSESTree . Identifier > ,
231+ tsTools : TSTools | null
225232) : void {
226233 if ( call . arguments . length < 1 ) {
227234 return ;
228235 }
229236 const url = call . arguments [ 0 ] ;
230- if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences ) ) {
237+ if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools ) ) {
231238 context . report ( { loc : url . loc , messageId : 'gotoWithoutResolve' } ) ;
232239 }
233240}
@@ -236,6 +243,7 @@ function checkShallowNavigationCall(
236243 context : RuleContext ,
237244 call : TSESTree . CallExpression ,
238245 resolveReferences : Set < TSESTree . Identifier > ,
246+ tsTools : TSTools | null ,
239247 messageId : string
240248) : void {
241249 if ( call . arguments . length < 1 ) {
@@ -244,7 +252,7 @@ function checkShallowNavigationCall(
244252 const url = call . arguments [ 0 ] ;
245253 if (
246254 ! expressionIsEmpty ( url ) &&
247- ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences )
255+ ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools )
248256 ) {
249257 context . report ( { loc : url . loc , messageId } ) ;
250258 }
@@ -255,7 +263,8 @@ function checkShallowNavigationCall(
255263function isResolveCall (
256264 ctx : FindVariableContext ,
257265 node : TSESTree . CallExpressionArgument ,
258- resolveReferences : Set < TSESTree . Identifier >
266+ resolveReferences : Set < TSESTree . Identifier > ,
267+ tsTools : TSTools | null
259268) : boolean {
260269 if (
261270 node . type === 'CallExpression' &&
@@ -266,9 +275,13 @@ function isResolveCall(
266275 ) {
267276 return true ;
268277 }
269- if ( node . type !== 'Identifier' ) {
278+ if ( node . type !== 'Identifier' || tsTools === null ) {
270279 return false ;
271280 }
281+ const tsNode = tsTools . service . esTreeNodeToTSNodeMap . get ( node ) ;
282+ console . log ( tsNode ) ;
283+ console . log ( tsTools . service . program . getTypeChecker ( ) . getTypeAtLocation ( tsNode ) ) ;
284+ /*
272285 const variable = ctx.findVariable(node);
273286 if (
274287 variable === null ||
@@ -279,6 +292,7 @@ function isResolveCall(
279292 return false;
280293 }
281294 return isResolveCall(ctx, variable.identifiers[0].parent.init, resolveReferences);
295+ */
282296}
283297
284298function expressionIsEmpty ( url : TSESTree . CallExpressionArgument ) : boolean {
0 commit comments