Skip to content

Commit e9f3504

Browse files
committed
feat(no-navigation-without-resolve): checking link shorthand attributes
1 parent 9e9fe1b commit e9f3504

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.changeset/icy-planets-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': minor
3+
---
4+
5+
feat(no-navigation-without-resolve): checking link shorthand attributes

packages/eslint-plugin-svelte/src/rules/no-navigation-without-resolve.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ export default createRule('no-navigation-without-resolve', {
8383
}
8484
}
8585
},
86+
SvelteShorthandAttribute(node) {
87+
if (
88+
context.options[0]?.ignoreLinks === true ||
89+
node.parent.parent.type !== 'SvelteElement' ||
90+
node.parent.parent.kind !== 'html' ||
91+
node.parent.parent.name.type !== 'SvelteName' ||
92+
node.parent.parent.name.name !== 'a' ||
93+
node.key.name !== 'href' ||
94+
node.value.type !== 'Identifier'
95+
) {
96+
return;
97+
}
98+
if (
99+
!expressionIsAbsolute(node.value, context) &&
100+
!expressionIsFragment(node.value, context) &&
101+
!isResolveCall(context, node.value, resolveReferences)
102+
) {
103+
context.report({ loc: node.loc, messageId: 'linkWithoutResolve' });
104+
}
105+
},
86106
SvelteAttribute(node) {
87107
if (
88108
context.options[0]?.ignoreLinks === true ||

0 commit comments

Comments
 (0)