feat(no-navigation-without-resolve): allow URL-derived hrefs
#1579
Closing issue
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
What version of ESLint are you using?
latest
What version of eslint-plugin-svelte are you using?
master
What did you do?
<script>
const one = new URL("https://svelte.dev");
const two = new URL("/blog", "https://svelte.dev");
</script>
<a href={one.href}>One</a>
<a href={two.href}>Two</a>
<a href={one.toString()}>One</a>
<a href={two.toString()}>Two</a>
<a href={one}>One</a> <!-- Not 100% sure this calls toString -->
<a href={two}>Two</a> <!-- Not 100% sure this calls toString -->
What did you expect to happen?
No error
What actually happened?
Error
Link to GitHub Repo with Minimal Reproducible Example
Will make a PR
Additional comments
No response
Pull request
Closes #1487
🦋 Changeset detected
Latest commit: 05adcc9
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| eslint-plugin-svelte | Minor |
Not sure what this means? .
Click here if you're a maintainer who wants to add another changeset to this PR
Try the Instant Preview in Online Playground
Install the Instant Preview to Your Local
npm i https://pkg.pr.new/eslint-plugin-svelte@05adcc9
Published Instant Preview Packages:
- eslint-plugin-svelte:
Hi,
sorry, but I don't see what you are referring to - a mailto: link should not be resolved - same with data: and ftp: - the are not internal page navigation and it would not make sense to add the base path to them.
So I think the proposed behaviour is correct. Am I missing something? Thanks!
Thanks for the update! I tested head eea4128 in a real SvelteKit app. I found 3 cases that the rule now accepts, but they break at runtime.
Setup: svelte.config.js has = '/base'. The page is src/routes/foo/+page.svelte, opened at /base/foo.
<script>
import { page } from '$app/state';
const mail = new URL('mailto:[email protected]');
const next = new URL('https://idp.example/cb');
</script>
<a href={mail.origin}>1</a>
<a href={`/login?redirect=${next}`}>2</a>
<a href={new URL('/blog', page.url).href}>3</a>
| # | Rule on main |
Rule on this PR | Rendered href |
Click result |
|---|---|---|---|---|
| 1 | error | no error | null (goes to /base/null) |
404 |
| 2 | error | no error | /login?redirect=https://idp.example/cb |
404: "did you mean to visit /base/login?..." |
| 3 | error | no error | http://localhost:5199/blog |
404: "did you mean to visit /base/blog?" |
1. origin
To clarify my earlier comment: I don't mean that mailto: links should be resolved. The problem is that URL.origin is the string "null" for mailto:, data:, file:, etc. So href={u.origin} is a relative link to ./null. It is not an absolute URL. origin is not part of #1487, so could you remove it?
Code: L507, L904
2. URL in the middle of a template or +
expressionIsAbsoluteUrl() now accepts a URL object. The template/binary checks accept the value if any part is absolute (L953, L964). So `/login?redirect=${url}` and '/login?redirect=' + url.href pass. Putting a URL in a query string is common. Could URLs only count when they are the first part?
3. new URL(path, base)
new URL('/blog', page.url) (or location.origin) gives a same-origin URL without the base path. This is exactly what the rule should catch. Could we only allow new URL() when the first argument is absolute, or the second argument is an absolute string literal (this still covers new URL('/blog', 'https://svelte.dev') from #1487)?
Could you also add invalid fixtures for these 3 cases? Thanks!
Hi, thanks for testing it in a real app and a great write-up - I misread your earlier comment about origin. All 3 are fixed now:
-
origin— removed. Onlyhref,toString(),toJSON()andString(url)are treated as absolute now. Added a test. -
URL in the middle of a template or
+— a URL now only counts when it is the leftmost part. Added a test. -
new URL(path, base)—new URL()is only accepted when the input or the base is absolute, sonew URL('/blog', page.url)andnew URL('/blog', location.origin)are reported. Two small extensions to your suggestion:- Single-argument
new URL(x)is always accepted, since without a base it throws unlessxis absolute. - The base can also be a URL object, not just a string literal, as long as it passes the same check (
const base = new URL('https://svelte.dev'); new URL('/blog', base)). A URL built on an unknown base (e.g.page.url) is still reported when used as a base or link itself.
Added a test for these as well.
- Single-argument
test(no-navigation-without-resolve): added tests with the URL class
• Sep 10, 2026, 3:03 PMfix(no-navigation-without-resolve): tracking global URL references properly
• Sep 18, 2026, 4:48 PM