Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-pugs-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix: Not reporting mailto: and other unusual schema addresses in no-nmavigation-without-resolve (and its deprecated versions)
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ function checkTemplateLiteral(
}

function checkLiteral(context: RuleContext, path: TSESTree.Literal): void {
const absolutePathRegex = /^(?:[+a-z]+:)?\/\//i;
if (!absolutePathRegex.test(path.value?.toString() ?? '')) {
if (!/^[+a-z]*:/i.test(path.value?.toString() ?? '')) {
context.report({ loc: path.loc, messageId: 'isNotPrefixedWithBasePath' });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function templateLiteralIsAbsolute(url: TSESTree.TemplateLiteral): boolean {
}

function urlValueIsAbsolute(url: string): boolean {
return url.includes('://');
return /^[+a-z]*:/i.test(url);
}

function expressionIsFragment(url: AST.SvelteLiteral | TSESTree.Expression): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function templateLiteralIsAbsolute(url: TSESTree.TemplateLiteral): boolean {
}

function urlValueIsAbsolute(url: string): boolean {
return url.includes('://');
return /^[+a-z]*:/i.test(url);
}

function expressionIsFragment(url: AST.SvelteLiteral | TSESTree.Expression): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
line: 4
column: 7
suggestions: null
- message: Found a goto() call with a url that isn't prefixed with the base path.
line: 5
column: 7
suggestions: null
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
import { goto } from '$app/navigation';

goto('/foo');
goto('/user:42');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

goto('http://localhost/foo/');
goto('https://localhost/foo/');
goto('mailto:[email protected]');
goto('tel:+123456789');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
line: 7
column: 9
suggestions: null
- message: Found a link with a url that isn't prefixed with the base path.
line: 8
column: 9
suggestions: null
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
<a href={'/foo'}>Click me!</a>
<a href={'/' + 'foo'}>Click me!</a>
<a href={value}>Click me!</a>
<a href={'/user:42'}>Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
line: 7
column: 9
suggestions: null
- message: Found a link with a url that isn't prefixed with the base path.
line: 8
column: 9
suggestions: null
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
<a href={'/foo#section'}>Click me!</a>
<a href={'/' + 'foo#section'}>Click me!</a>
<a href={value}>Click me!</a>
<a href={'/foo#section:42'}>Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
<a href={'http' + '://svelte.dev'}>Click me!</a>
<a href={'https' + '://svelte.dev'}>Click me!</a>
<a href={`${protocol}://svelte.dev`}>Click me!</a>
<a href="mailto:[email protected]">Click me!</a>
<a href="tel:+123456789">Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<a href={'#' + 'section'}>Click me!</a>
<a href={'#' + section}>Click me!</a>
<a href={`#${section}`}>Click me!</a>
<a href={'#user:42'}>Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
line: 8
column: 9
suggestions: null
- message: Found a link with a url that isn't resolved.
line: 9
column: 9
suggestions: null
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<a href={'/foo#section'}>Click me!</a>
<a href={'/' + 'foo#section'}>Click me!</a>
<a href={value}>Click me!</a>
<a href={'/foo#section:42'}>Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
line: 8
column: 9
suggestions: null
- message: Found a link with a url that isn't resolved.
line: 9
column: 9
suggestions: null
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<a href={'/foo'}>Click me!</a>
<a href={'/' + 'foo'}>Click me!</a>
<a href={value}>Click me!</a>
<a href={'/user:42'}>Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
<a href={'http' + '://svelte.dev'}>Click me!</a>
<a href={'https' + '://svelte.dev'}>Click me!</a>
<a href={`${protocol}://svelte.dev`}>Click me!</a>
<a href="mailto:[email protected]">Click me!</a>
<a href="tel:+123456789">Click me!</a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<a href={'#' + 'section'}>Click me!</a>
<a href={'#' + section}>Click me!</a>
<a href={`#${section}`}>Click me!</a>
<a href={'#user:42'}>Click me!</a>
Loading