no-navigation-without-resolve: goto('', { shallow: true }) is reported, but pushState('') / replaceState('') are allowed
#1609
no-navigation-without-resolve: goto('', { shallow: true }) is reported, but pushState('') / replaceState('') are allowedDevelopment PRs
Fixes #1609
SvelteKit 3 deprecates pushState() / replaceState() in favour of goto(url, { state, shallow: true }) (see the shallow routing docs). The rule already allowed pushState('') / replaceState(''), but reported the equivalent goto('', { shallow: true }).
goto() now allows an empty URL when its options have a truthy shallow (matching SvelteKit's if (opts.shallow)). The options are resolved with the existing lookupProperty() helper, so they can be inline, in a variable or nested in an object (e.g. goto('', config.opts)), and spreads and computed keys are applied in order. Still reported:
- non-empty URLs, even with
shallow: true(e.g.goto('/foo', { shallow: true })) goto('')without a truthyshallow- options where
shallow: truemay be overridden by a later spread or a computed key that cannot be statically resolved
While addressing review, two fixes that apply to the whole rule (each in its own commit, with its own changeset):
- Variables are only followed if they are
constor never reassigned (likegetStaticValue()), so e.g.let url = resolve('/'); url = '/foo'; goto(url);is now reported. - TypeScript
as,satisfies,!and<T>wrappers are looked through, so e.g.goto('', { shallow: true } as const)orconst paths = [resolve('/')] as constare no longer reported.
Docs and changesets are included.
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
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?
9.39.5
What version of eslint-plugin-svelte are you using?
3.23.1
What did you do?
Configuration
import svelte from 'eslint-plugin-svelte';
export default [
...svelte.configs.recommended,
{
files: ['**/*.svelte'],
rules: { 'svelte/no-navigation-without-resolve': 'error' }
}
];
<script>
import { goto, pushState, replaceState } from '$app/navigation';
pushState('', {});
replaceState('', {});
goto('', { shallow: true, state: {} });
goto('', { shallow: true, replace: true, state: {} });
</script>
SvelteKit 3 deprecates pushState / replaceState in favour of goto(url, { state, shallow: true }) / goto(url, { state, shallow: true, replace: true }) (see the @deprecated notes in @sveltejs/kit/types/index.d.ts). The rule accepts an empty URL for pushState('') / replaceState(''), which the rule docs list as valid shallow routing, but reports the same call written the way Kit 3 recommends.
What did you expect to happen?
No errors: the two goto calls are the Kit 3 replacements for the pushState / replaceState calls above them, which the rule already accepts.
What actually happened?
src/Repro.svelte
6:7 error Unexpected goto() call without resolve() svelte/no-navigation-without-resolve
7:7 error Unexpected goto() call without resolve() svelte/no-navigation-without-resolve
✖ 2 problems (2 errors, 0 warnings)
Link to GitHub Repo with Minimal Reproducible Example
https://github.com/jose-manuel-silva/repro-eslint-goto-shallow
Additional comments
In the source, checkGotoCall passes {} to isValueAllowed while checkShallowNavigationCall passes { allowEmpty: true }, and goto's options argument is never read. Same on main (90d7b09). Draft #1605 keeps allowEmpty limited to pushState / replaceState, so it doesn't change this. A possible fix: pass { allowEmpty: true } in checkGotoCall when the second argument is an object literal with shallow: true (or allow '' for goto in general, since it resolves to the current URL). @sveltejs/kit 3.1.0, svelte 5.57.2. Related: #1481.
Thanks, I haven't gotten to updating the rule for kit 3. Is there some documentation where it says your examples are valid (it makes sense, but I'd like to have something to back it up)?
Yes. The shallow routing docs (svelte.dev/docs/kit/shallow-routing) open with this exact call:
goto('', {
state: { showModal: true },
shallow: true
});
Further down, the LEGACY note says:
In SvelteKit 2 this functionality was achieved using
pushStateandreplaceState, which are now deprecated. Usegotowithshallow: trueinstead, and use thereplaceoption when replacing the current history entry.
The type definitions in @sveltejs/kit 3.1.0 (types/index.d.ts) say the same thing:
/** @deprecated Use `goto(url, { state, shallow: true })` instead. */
export function pushState(url: string | URL, state: App.PageState): Promise<void>;
/** @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead. */
export function replaceState(url: string | URL, state: App.PageState): Promise<void>;
So goto('', { shallow: true, ... }) is Kit 3's version of pushState('', ...), which the rule already allows. It's also the first example on the shallow-routing page.