@@ -90,55 +90,25 @@ export default createRule('no-navigation-without-resolve', {
9090 }
9191 }
9292 } ,
93- SvelteShorthandAttribute ( node ) {
94- if (
95- ignoreLinks ||
96- node . parent . parent . type !== 'SvelteElement' ||
97- node . parent . parent . kind !== 'html' ||
98- node . parent . parent . name . type !== 'SvelteName' ||
99- node . parent . parent . name . name !== 'a' ||
100- node . key . name !== 'href' ||
101- node . value . type !== 'Identifier'
102- ) {
103- return ;
104- }
105- if (
106- ! expressionIsAbsolute ( new FindVariableContext ( context ) , node . value ) &&
107- ! expressionIsFragment ( new FindVariableContext ( context ) , node . value ) &&
108- ! isResolveCall ( new FindVariableContext ( context ) , node . value , resolveReferences )
109- ) {
110- context . report ( { loc : node . loc , messageId : 'linkWithoutResolve' } ) ;
111- }
112- } ,
113- SvelteAttribute ( node ) {
114- if (
115- ignoreLinks ||
116- node . parent . parent . type !== 'SvelteElement' ||
117- node . parent . parent . kind !== 'html' ||
118- node . parent . parent . name . type !== 'SvelteName' ||
119- node . parent . parent . name . name !== 'a' ||
120- node . key . name !== 'href'
121- ) {
122- return ;
123- }
124- if (
125- ( node . value [ 0 ] . type === 'SvelteLiteral' &&
126- ! expressionIsNullish ( new FindVariableContext ( context ) , node . value [ 0 ] ) &&
127- ! expressionIsAbsolute ( new FindVariableContext ( context ) , node . value [ 0 ] ) &&
128- ! expressionIsFragment ( new FindVariableContext ( context ) , node . value [ 0 ] ) ) ||
129- ( node . value [ 0 ] . type === 'SvelteMustacheTag' &&
130- ! expressionIsNullish ( new FindVariableContext ( context ) , node . value [ 0 ] . expression ) &&
131- ! expressionIsAbsolute ( new FindVariableContext ( context ) , node . value [ 0 ] . expression ) &&
132- ! expressionIsFragment ( new FindVariableContext ( context ) , node . value [ 0 ] . expression ) &&
133- ! isResolveCall (
134- new FindVariableContext ( context ) ,
135- node . value [ 0 ] . expression ,
93+ ...( ! ignoreLinks && {
94+ SvelteShorthandAttribute ( node ) {
95+ if ( ! isLinkAttributeOk ( context , node , node . value , resolveReferences ) ) {
96+ context . report ( { loc : node . loc , messageId : 'linkWithoutResolve' } ) ;
97+ }
98+ } ,
99+ SvelteAttribute ( node ) {
100+ if (
101+ ! isLinkAttributeOk (
102+ context ,
103+ node ,
104+ node . value [ 0 ] . type === 'SvelteMustacheTag' ? node . value [ 0 ] . expression : node . value [ 0 ] ,
136105 resolveReferences
137- ) )
138- ) {
139- context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
106+ )
107+ ) {
108+ context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
109+ }
140110 }
141- }
111+ } )
142112 } ;
143113 }
144114} ) ;
@@ -250,11 +220,30 @@ function checkShallowNavigationCall(
250220 }
251221}
252222
223+ function isLinkAttributeOk (
224+ context : RuleContext ,
225+ attribute : AST . SvelteAttribute | AST . SvelteShorthandAttribute ,
226+ value : TSESTree . Expression | AST . SvelteLiteral ,
227+ resolveReferences : Set < TSESTree . Identifier >
228+ ) : boolean {
229+ return (
230+ attribute . parent . parent . type !== 'SvelteElement' ||
231+ attribute . parent . parent . kind !== 'html' ||
232+ attribute . parent . parent . name . type !== 'SvelteName' ||
233+ attribute . parent . parent . name . name !== 'a' ||
234+ attribute . key . name !== 'href' ||
235+ expressionIsNullish ( new FindVariableContext ( context ) , value ) ||
236+ expressionIsAbsolute ( new FindVariableContext ( context ) , value ) ||
237+ expressionIsFragment ( new FindVariableContext ( context ) , value ) ||
238+ isResolveCall ( new FindVariableContext ( context ) , value , resolveReferences )
239+ ) ;
240+ }
241+
253242// Helper functions
254243
255244function isResolveCall (
256245 ctx : FindVariableContext ,
257- node : TSESTree . CallExpressionArgument ,
246+ node : TSESTree . CallExpressionArgument | AST . SvelteLiteral ,
258247 resolveReferences : Set < TSESTree . Identifier >
259248) : boolean {
260249 if (
0 commit comments