feat(no-navigation-without-resolve): recognizing resolved values with queries and fragments
#1482
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?
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}`Pull request
🦋 Changeset detected
Latest commit: 6c8c686
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 to learn what changesets are.
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@6c8c686
Published Instant Preview Packages:
- eslint-plugin-svelte:
THIS SHOULD NOT BE MERGED YET
Hi, the code looks good (it's mostly mine, heh 😅), so I'm OK with the code (could be split into 2 PRs, but whatever, they are in 2 commits...). However, I just found that the Svelte team is considering adding this functionality into resolve() (and there is as of now merged but unreleased PR that adds support for passing query and fragment as strings into resolve()). I have asked them how they want to proceed and I'd like to wait fro their answer. Maybe we shouldn't do this PR after all as the functionality will be included in resolve()...
I saw that, what an unfortunate timing on my part. I just wanted to push progress forward.
@sacrosanctic Can you add a "Closes #1327"?
I'm confused on why this hasn't moved I must be missing something @marekdedic
Right now I cannot do this very basic thing:
<a href={'/abc?x=' + '1'} (or equivalent where the '1' is a variable)
-> it complains about not using resolve
add resolve
<a href={resolve('/abc?x=' + '1')}
-> resolve works fine and provides the correct link but it gives ts-2345 error
Only solution afaik is 1) not using resolve (bad) and therefore then 2) adding eslint-disable-next-line svelte/no-navigation-without-resolve so things don't light up "red" in IDE. This is what I'm forced to do at present to do a simple a with a query param.
So this definitely seems like a linting issue, and has nothing to do with resolve() and has nothing to do with goto(): resolve works as is and renders a correct "href" on the a, as noted above, and goto is a totally different programmatic solution that's not the same as a simple html "link" (although it may need similar fixing which I think was done already). Imo regardless of those other solutions this is simply a linting bug as the above URL is totally acceptable in every way and it's a extremely fundamental part of HTML.
Regarding "user could screw up the query param" noted in sveltejs/kit#14750 (comment).... Sure. Don't relax the lint rule so much that obvious problems are allowed. But imo mostly irrelevant as that can be solved elsewhere. A rule that dissallows the 99% to worry about the 1% is not a good rule imo.
This hasn't moved because when I last checked, it seemed that SvelteKit would add support for queries & fragments to resolve(). It seems that that is still the plan, but stalled somewhat.
If that is merged, I think we'll want to disallow bypassing resolve with queries and fragments. So I'm a little hesitant to merge this now, as we could well be reverting this change soon-ish. @ota-meshi what do you think?
I don't think we'll be adding those options to resolve anytime soon (see sveltejs/kit#14750 (comment)). The current PR that's open doesn't fulfil that requirement. It's probably better to go ahead with this PR as the eslint rule is currently too restrictive but is enabled by default.
Ok, so I'd be for merging this. LGTM.
@sacrosanctic Could you rebase please? I think I introduced some merge conflicts, sorry...
@marekdedic I was thinking "I don't remember there being conflicts when I opened this."
Resolved the merge conflicts, I gave expressionIsResolvedPathname context, but didn't use it. Unsure if it's needed. These changes does not address @jycouet's comments.
edit: runner didn't like that so I removed it.
@sacrosanctic Sorry to bother, but do you have the time to look at this again? If not, that's okay and I'll do it :)
I'll take a stab at it tonight. If you don't hear from me by then. It's cause I didn't have time.
Hi @ota-meshi @baseballyama @sacrosanctic. I took another stab at it, rebased it and fixed all of the review comments. The result is in #1605 - can you please take a look? Thanks!
feat(no-navigation-without-resolve): not reporting pure query URLs
• Dec 14, 2025, 7:21 PMfeat(no-navigation-without-resolve): recognizing resolved values with queries and fragments
• Dec 14, 2025, 10:04 PM