@@ -4,6 +4,7 @@ import { ReferenceTracker } from '@eslint-community/eslint-utils';
44import { findVariable } from '../utils/ast-utils.js' ;
55import type { RuleContext } from '../types.js' ;
66import type { AST } from 'svelte-eslint-parser' ;
7+ import { type TSTools , getTypeScriptTools } from 'src/utils/ts-utils/index.js' ;
78
89export default createRule ( 'no-navigation-without-resolve' , {
910 meta : {
@@ -47,6 +48,8 @@ export default createRule('no-navigation-without-resolve', {
4748 ]
4849 } ,
4950 create ( context ) {
51+ const tsTools = getTypeScriptTools ( context ) ;
52+
5053 let resolveReferences : Set < TSESTree . Identifier > = new Set < TSESTree . Identifier > ( ) ;
5154 return {
5255 Program ( ) {
@@ -59,7 +62,7 @@ export default createRule('no-navigation-without-resolve', {
5962 } = extractFunctionCallReferences ( referenceTracker ) ;
6063 if ( context . options [ 0 ] ?. ignoreGoto !== true ) {
6164 for ( const gotoCall of gotoCalls ) {
62- checkGotoCall ( context , gotoCall , resolveReferences ) ;
65+ checkGotoCall ( context , gotoCall , resolveReferences , tsTools ) ;
6366 }
6467 }
6568 if ( context . options [ 0 ] ?. ignorePushState !== true ) {
@@ -68,6 +71,7 @@ export default createRule('no-navigation-without-resolve', {
6871 context ,
6972 pushStateCall ,
7073 resolveReferences ,
74+ tsTools ,
7175 'pushStateWithoutResolve'
7276 ) ;
7377 }
@@ -78,6 +82,7 @@ export default createRule('no-navigation-without-resolve', {
7882 context ,
7983 replaceStateCall ,
8084 resolveReferences ,
85+ tsTools ,
8186 'replaceStateWithoutResolve'
8287 ) ;
8388 }
@@ -101,7 +106,7 @@ export default createRule('no-navigation-without-resolve', {
101106 ( node . value [ 0 ] . type === 'SvelteMustacheTag' &&
102107 ! expressionIsAbsolute ( node . value [ 0 ] . expression ) &&
103108 ! expressionIsFragment ( node . value [ 0 ] . expression ) &&
104- ! isResolveCall ( context , node . value [ 0 ] . expression , resolveReferences ) )
109+ ! isResolveCall ( context , node . value [ 0 ] . expression , resolveReferences , tsTools ) )
105110 ) {
106111 context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
107112 }
@@ -185,13 +190,14 @@ function extractFunctionCallReferences(referenceTracker: ReferenceTracker): {
185190function checkGotoCall (
186191 context : RuleContext ,
187192 call : TSESTree . CallExpression ,
188- resolveReferences : Set < TSESTree . Identifier >
193+ resolveReferences : Set < TSESTree . Identifier > ,
194+ tsTools : TSTools | null
189195) : void {
190196 if ( call . arguments . length < 1 ) {
191197 return ;
192198 }
193199 const url = call . arguments [ 0 ] ;
194- if ( ! isResolveCall ( context , url , resolveReferences ) ) {
200+ if ( ! isResolveCall ( context , url , resolveReferences , tsTools ) ) {
195201 context . report ( { loc : url . loc , messageId : 'gotoWithoutResolve' } ) ;
196202 }
197203}
@@ -200,13 +206,14 @@ function checkShallowNavigationCall(
200206 context : RuleContext ,
201207 call : TSESTree . CallExpression ,
202208 resolveReferences : Set < TSESTree . Identifier > ,
209+ tsTools : TSTools | null ,
203210 messageId : string
204211) : void {
205212 if ( call . arguments . length < 1 ) {
206213 return ;
207214 }
208215 const url = call . arguments [ 0 ] ;
209- if ( ! expressionIsEmpty ( url ) && ! isResolveCall ( context , url , resolveReferences ) ) {
216+ if ( ! expressionIsEmpty ( url ) && ! isResolveCall ( context , url , resolveReferences , tsTools ) ) {
210217 context . report ( { loc : url . loc , messageId } ) ;
211218 }
212219}
@@ -216,7 +223,8 @@ function checkShallowNavigationCall(
216223function isResolveCall (
217224 context : RuleContext ,
218225 node : TSESTree . CallExpressionArgument ,
219- resolveReferences : Set < TSESTree . Identifier >
226+ resolveReferences : Set < TSESTree . Identifier > ,
227+ tsTools : TSTools | null
220228) : boolean {
221229 if (
222230 node . type === 'CallExpression' &&
@@ -227,6 +235,12 @@ function isResolveCall(
227235 ) {
228236 return true ;
229237 }
238+ if ( node . type === 'Identifier' && tsTools !== null ) {
239+ const tsNode = tsTools . service . esTreeNodeToTSNodeMap . get ( node ) ;
240+ console . log ( tsNode ) ;
241+ console . log ( tsTools . service . program . getTypeChecker ( ) . getTypeAtLocation ( tsNode ) ) ;
242+ }
243+ /*
230244 if (node.type === 'Identifier') {
231245 const variable = findVariable(context, node);
232246 if (
@@ -239,6 +253,7 @@ function isResolveCall(
239253 return true;
240254 }
241255 }
256+ */
242257 return false ;
243258}
244259
0 commit comments