feat(no-navigation-without-resolve): recognizing resolved values with queries and fragments
#1605
Closing issues
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.34.0
What version of eslint-plugin-svelte are you using?
3.12.1
What did you do?
Configuration
// ESLint flat config for SvelteKit + TypeScript + Prettier // Migrated from .eslintrc.cjs to eslint.config.js (Flat Config)import js from "@eslint/js"; import eslintConfigPrettier from "eslint-config-prettier/flat"; import svelte from "eslint-plugin-svelte"; import globals from "globals"; import svelteConfig from "./svelte.config.js";
// Use the typescript-eslint aggregator for flat config presets // (requires devDependency: "typescript-eslint") import tseslint from "typescript-eslint";
export default [ // Ignore generated and build artifacts { ignores: [ // migrated from .eslintignore ".DS_Store", "node_modules", "build", ".svelte-kit", "package", ".env", ".env.*", "pnpm-lock.yaml", "package-lock.json", "yarn.lock", // additional "dist", ".vite", "drizzle", "supabase//migrations/" ] },
// Base language options and globals
{
languageOptions: {
ecmaVersion: 2020,
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
// Svelte built-in types
$$Generic: "readonly",
App: "readonly"
}
}
},
// Core JS recommended rules
js.configs.recommended,
// TypeScript rules (no type-aware rules by default)
...tseslint.configs.recommended,
// Svelte plugin recommended rules for Svelte files
...svelte.configs["flat/recommended"],
{
files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
languageOptions: {
parserOptions: {
// Ensure TS within <script lang="ts"> is parsed
parser: tseslint.parser,
projectService: true,
extraFileExtensions: [".svelte"],
// Pass through SvelteKit config for better rule behavior
svelteConfig
}
}
},
// Turn off formatting-related Svelte rules to avoid conflicts with Prettier
...svelte.configs["flat/prettier"],
// Project-wide rule tweaks
{
rules: {
"require-yield": "off",
// disabled because it doesn't support search params
"svelte/no-navigation-without-resolve": "off"
}
},
// Keep Prettier last to disable conflicting stylistic rules
eslintConfigPrettier
];
<a
href={`/?redirect=${encodeURIComponent(`${page.url.pathname}${page.url.search}`)}`}
class="bg-base-200/50 text-base-content hover:bg-base-300 flex h-12 items-center gap-2 rounded-lg p-2 transition-colors"
>
<span class="flex h-full flex-1 items-center justify-center font-semibold">Sign In</span>
</a>
What did you expect to happen?
I expect to be able to use search params in links and goto without either TS or eslint complaining.
What actually happened?
As far as I can tell, there's no way to make this href work such that it satisfies the resolve() type and the no-navigation-without-resolve rule.
Link to GitHub Repo with Minimal Reproducible Example
eslint complains:
href={`/?redirect=${encodeURIComponent(`${page.url.pathname}${page.url.search}`)}`}
href={resolve("/")+`?redirect=${encodeURIComponent(`${page.url.pathname}${page.url.search}`)}`}
typescript complains:
href={resolve(`/?redirect=${encodeURIComponent(`${page.url.pathname}${page.url.search}`)}`)}
Additional comments
The only way to make it work is to assert the type:
href={resolve(`/?redirect=${encodeURIComponent(`${page.url.pathname}${page.url.search}`)}` as Pathname & {})}
The same problem also occurs for hash (#) urls.
I think href and goto accepting any of the following should help:
type Href = ResolvedPathname || `${ResolvedPathname}?${string}` || `${ResolvedPathname}#${string}`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?
10.4.0
What version of eslint-plugin-svelte are you using?
3.17.1
What did you do?
import { replaceState } from '$app/navigation';
...
replaceState(`#hash`, {}); // Unexpected replaceState() call without resolve(). (eslint svelte/no-navigation-without-resolve)
What did you expect to happen?
No lint error
What actually happened?
Unexpected replaceState() call without resolve(). (eslint svelte/no-navigation-without-resolve)
Link to GitHub Repo with Minimal Reproducible Example
Will provide later if needed.
Additional comments
No response
Pull request
Continuation of #1482 (originally #1444), rebased onto current main, with the review feedback from #1482 addressed.
What this does
svelte/no-navigation-without-resolve no longer reports:
- Resolved URLs followed by a query string or a fragment, e.g.
resolve('/foo') + '?page=2',`${resolve('/foo')}#section`,resolve('/') + (searchParams.size ? `?${searchParams}` : ''), or<a href="{resolve('/foo')}?page=2">. A URL counts as resolved if it starts withresolve()/asset()or aResolvedPathnamevalue. - Query-only and fragment-only URLs, e.g.
goto('?page=2'),<a href="?{searchParams}">orreplaceState('#top', {}), as they keep the current path. Fragment-only URLs were previously only allowed in links.
A resolved value followed by anything other than a query or a fragment (e.g. resolve('/foo') + '/bar') is still reported, since it bypasses the route type-checking of resolve(). This follows the discussion in sveltejs/kit#14750.
URLs may be built with + concatenation, template literals, multi-part href attributes, variables, array elements, object properties, {#each} items and ternaries, in any combination.
Behaviour change for href attributes
Previously, only the first part of a multi-part href attribute was checked, so <a href="{resolve('/foo')}/bar"> was not reported. All parts are now checked, so it is reported. To fix such links, pass the whole path to resolve() (e.g. resolve('/blog/[slug]', { slug })) and start a query or fragment with a literal ? or # (e.g. href="{resolve('/search')}?{params}").
Leading and trailing whitespace in an href is ignored, as browsers strip it, so <a href=" {resolve('/foo')} "> is not reported. Whitespace between the parts is kept, as it stays in the URL.
Review feedback from #1482
- Fixed a crash on template literals containing only
resolve()(or nothing). - Concatenation is only recognised for the
+operator. - Replaced the separate
BinaryExpression/TemplateLiteralhandling with a single check over the URL's parts. Variables, member accesses and{#each}items are expanded along the way. Cyclic definitions are guarded by a set of the variables expanded on the current path, rather than aFindVariableContext, because a shared one would make the branches of a ternary interfere with each other, and a fresh one per branch loops forever on cyclic definitions. - Documented queries, fragments and
ResolvedPathnamein the rule docs.
Related: #1381 adds suffix support behind an option; this PR enables it by default.
🦋 Changeset detected
Latest commit: 59c4a9a
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@59c4a9a
Published Instant Preview Packages:
- eslint-plugin-svelte:
Should be resolved and I also added a note about the comment format to AGENTS.md.
Thanks for the review!
- PR description: The eslint-disable was indeed dropped during a rebase. I generally updated it to reflect the current state of the PR, thanks!
- getAmbientModules(): the ResolvedPathname type is now cached per type checker (a WeakMap), so it's looked up once per program rather than on every call. It's in its own commit, so I can move it to a separate PR if you'd prefer.
feat(no-navigation-without-resolve): not reporting pure query and fragment URLs
• Dec 14, 2025, 7:21 PMfeat(no-navigation-without-resolve): recognizing resolved values with queries and fragments
• Dec 14, 2025, 10:04 PMfix(no-navigation-without-resolve): fixed a crash on template literals with fewer than two parts
• Oct 9, 2026, 11:57 AMfix(no-navigation-without-resolve): only allowing suffix concatenation with the + operator
• Oct 9, 2026, 12:03 PMchore(no-navigation-without-resolve): consistently passing findContext through recursive calls
• Oct 9, 2026, 12:14 PMfix(no-navigation-without-resolve): only allowing a query or fragment after a resolved value
• Oct 9, 2026, 1:49 PMdocs(no-navigation-without-resolve): documented queries, fragments and ResolvedPathname
• Oct 9, 2026, 1:58 PMchore(no-navigation-without-resolve): using JSDoc for function and type comments
• Oct 27, 2026, 9:56 AMdocs(AGENTS.md): documented using JSDoc for declaration comments
• Oct 27, 2026, 9:56 AMtest(no-navigation-without-resolve): added tests combining member access with queries and fragments
• Oct 29, 2026, 10:46 AMperf(no-navigation-without-resolve): caching the ResolvedPathname type per type checker
• Nov 3, 2026, 11:59 PM