no-navigation-without-resolve: error message should explain when to use rel="external"
#1615
no-navigation-without-resolve: error message should explain when to use rel="external"Development PR
Rebuilds svelte/no-navigation-without-resolve to check statically identifiable URL patterns while skipping unknown values by default. The new strict option also reports values the analysis cannot verify.
This is a base-path navigation policy check, not proof that a URL is broken: the rule does not know the deployment origin or routing configuration.
Docs: no-navigation-without-resolve.md
Behavior
- Check links,
<area>, SVG<a>, form actions and submit-controlformaction, plusgoto(),pushState(),replaceState(),preloadData()andpreloadCode(). - Accept query/hash-only destinations, empty URLs,
page.url, query/hash suffixes afterresolve(), and nullableResolvedPathnamevalues in URL-taking sinks. Relative URLs usually keep the base path, so they are reported only withstrict(orallowRelativePaths: false). - Respect form ownership (including explicit
formattributes), submit-control types and effectiveformmethod; skip non-submitting controls and dialog submissions. Therel="external"exemption for links/forms expresses lint policy; it does not guarantee that SvelteKit routing oruse:enhanceis bypassed. - HTTP(S) and protocol-relative URLs in navigation calls may be same-origin: skip them by default and report them as unverifiable with
strict. Report non-HTTP(S) URLs in these calls. - Check only the supported first
preloadCode()argument: a root-relative pathname on Kit 2, a route ID on Kit 3. The pathname requirement is not relaxed byallowRelativePaths. - Follow variables, reassignments,
$state(),$derived(),$props()defaults, arrays, objects,{#each}and declared TypeScript literal types. Bound recursive evaluation, handle empty-string fallbacks and null/undefined defaults, and verify bindings before treating calls as read-only. - Provide targeted diagnostics and
resolve()/asset()suggestions. Run only on SvelteKit 2.26+; deprecateignoreGoto,ignoreLinks,ignorePushStateandignoreReplaceState.
The rule documentation describes accepted patterns, strict-mode behavior and analysis limitations. One minor changeset covers the change.
Specification checks
Rechecked SvelteKit's link options, form actions and navigation API, together with the Kit 2.26 implementation for version-specific behavior.
Validation
- Full plugin test suite: 1,710 passing. TypeScript, ESLint and formatting checks pass.
Real-project check
I ran the final rule (31948b7c) on 55 popular SvelteKit repositories, without type information. Each project used SvelteKit 2.70.3 or 3.1.1, matching its declared major version (pluja/whishper uses SvelteKit 1, so the rule does not run there).
- Default mode: 1,698 reports. All are root-relative paths such as
href="/about"orgoto('/login'). 1,674 have the path written on the reported line, and I checked all 24 others by hand: they hold literal paths like`/trail/view/${id}`. The only false positive found (base || '/'in huggingface/chat-ui) is fixed in this PR. - Existing
eslint-disablecomments: these repositories have 155 comments that disable this rule. 152 of those lines are no longer reported. The other 3 are root-relative paths. One of them is a link to a backend API, and the message suggestsrel="external"for that case. - Current rule (
main,8c8a881e): 3,151 reports on the same repositories, with the same setup. - Strict mode: 3,034 reports. The extra reports are unknown values (by design) and links with spread attributes.
- Not app code: most reports in
sveltejs/kit(test apps) andsveltejs/svelte.dev(tutorial apps) come from code that is not linted in practice. - Private app: I also ran the rule with type information on a large private SvelteKit monorepo (5 apps). Default mode gives 30 reports, all root-relative literals. The current rule gives 205 reports there, and at least 107 of them are false positives.
- No crashes.
Repositories
Issues
Fixes #1314, fixes #1327, fixes #1353, fixes #1487, fixes #1492, fixes #1502, fixes #1609, fixes #1615
- #1526: by design, unknown
data.pathis reported only withstrict; declared literal types can make a value statically identifiable. - #1524 (
redirect()): not included. Waiting for sveltejs/kit#17623. - Not covered: #1324 (
<link>), #1352 (custom resolve functions; unknown results are skipped in default mode).
Issue
Description
Unexpected href link without resolve(). tells users to wrap the href in resolve() but that's not right for paths outside the SvelteKit app. A clearer error message would explain that same-origin links such as /admin, which are not part of the SvelteKit app, should be marked as external. This is currently only mentioned in the docs, so folks may get confused seeing this error message.
Proposal
linkWithoutResolve:Links to routes in this app should use resolve() from '$app/paths'. If the link points outside this app (another site, or a path served by a different app), add rel="external".gotoWithoutResolve/pushStateWithoutResolve/replaceStateWithoutResolve:Navigation to routes in this app should use resolve() from '$app/paths'. To navigate outside this app, use window.location.- (Optional, TS only) When the href is a string literal that doesn't match any route in
$app/types, report a dedicated message, e.g.'/admin' is not a route in this app. If it belongs to another app, add rel="external"; otherwise check for a typo.
Related: #1481
I think adding more descriptive error messages would indeed be useful. I'm not sure how long they can/should be in general.
Also, I don't really want to steer users towards just slapping rel="external" on links - an external link should be an absolute URL most of the time. So point 1 maybe isn't the right message? 2 is spot on. 3 would be a little bit harder to implement, but also makes sense.
Given the other pending improvements to the rule, I probably won't get to this in the foreseeable future. Happy to review a PR.