-
-
Notifications
You must be signed in to change notification settings - Fork 58
feat: replaced no-navigation-without-base with no-navigation-without-resolve #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ota-meshi
merged 5 commits into
sveltejs:main
from
marekdedic:no-navigation-without-resolve
Sep 3, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6dd1135
chore: deprecated the no-goto-without-base rule
marekdedic 9223298
test(no-navigation-without-resolve): added rule tests
marekdedic 7d993da
feat: added the no-navigation-without-resolve rule
marekdedic 6e26629
Update docs/rules/no-navigation-without-resolve.md
ota-meshi e3001b3
chore: pnpm run update
marekdedic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'eslint-plugin-svelte': minor | ||
--- | ||
|
||
feat: added the no-navigation-without-resolve rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'eslint-plugin-svelte': minor | ||
--- | ||
|
||
chore: deprecated the no-navigation-without-base rule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
pageClass: 'rule-details' | ||
sidebarDepth: 0 | ||
title: 'svelte/no-navigation-without-resolve' | ||
description: 'disallow using navigation (links, goto, pushState, replaceState) without a resolve()' | ||
since: 'v2.36.0-next.9' | ||
--- | ||
|
||
# svelte/no-navigation-without-resolve | ||
|
||
> disallow using navigation (links, goto, pushState, replaceState) without a resolve() | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports navigation using HTML `<a>` tags, SvelteKit's `goto()`, `pushState()` and `replaceState()` functions without resolving a relative URL. All four of these may be used for navigation, with `goto()`, `pushState()` and `replaceState()` being intended solely for iternal navigation (i.e. not leaving the site), while `<a>` tags may be used for both internal and external navigation. When using any way of internal navigation, the URL must be resolved using SvelteKit's `resolve()`, otherwise the site may break. For programmatic navigation to external URLs, using `window.location` is advised. | ||
|
||
This rule checks all 4 navigation options for the presence of the `resolve()` fucntion call, with an exception for `<a>` links to absolute URLs (and fragment URLs), which are assumed to be used for external navigation and so do not require the `resolve()` function, and for shallow outing functions with an empty string as the path, which keeps the current URL. | ||
|
||
<!--eslint-skip--> | ||
|
||
```svelte | ||
<script> | ||
/* eslint svelte/no-navigation-without-resolve: "error" */ | ||
|
||
import { goto, pushState, replaceState } from '$app/navigation'; | ||
import { resolve } from '$app/paths'; | ||
|
||
// ✓ GOOD | ||
goto(resolve('/foo/')); | ||
|
||
pushState(resolve('/foo/'), {}); | ||
pushState('', {}); | ||
|
||
replaceState(resolve('/foo/'), {}); | ||
replaceState('', {}); | ||
|
||
// ✗ BAD | ||
goto('/foo'); | ||
goto('/foo' + resolve('/bar')); | ||
goto(resolve('/foo') + '/bar'); | ||
|
||
pushState('/foo', {}); | ||
replaceState('/foo', {}); | ||
</script> | ||
|
||
<!-- ✓ GOOD --> | ||
<a href={resolve('/foo/')}>Click me!</a> | ||
<a href="https://svelte.dev">Click me!</a> | ||
|
||
<!-- ✗ BAD --> | ||
<a href="/foo">Click me!</a> | ||
<a href={'/foo'}>Click me!</a> | ||
``` | ||
|
||
## :wrench: Options | ||
|
||
```json | ||
{ | ||
"svelte/no-navigation-without-resolve": [ | ||
"error", | ||
{ | ||
"ignoreGoto": false, | ||
"ignoreLinks": false, | ||
"ignorePushState": false, | ||
"ignoreReplaceState": false | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- `ignoreGoto` ... Whether to ignore all `goto()` calls. Default `false`. | ||
- `ignoreLinks` ... Whether to ignore all `<a>` tags. Default `false`. | ||
- `ignorePushState` ... Whether to ignore all `pushState()` calls. Default `false`. | ||
- `ignoreReplaceState` ... Whether to ignore all `replaceState()` calls. Default `false`. | ||
|
||
## :books: Further Reading | ||
|
||
- [`resolve()` documentation](https://svelte.dev/docs/kit/$app-paths#resolve) | ||
- [Shallow routing](https://svelte.dev/docs/kit/shallow-routing) | ||
- [`goto()` documentation](https://svelte.dev/docs/kit/$app-navigation#goto) | ||
- [`pushState()` documentation](https://svelte.dev/docs/kit/$app-navigation#pushState) | ||
- [`replaceState()` documentation](https://svelte.dev/docs/kit/$app-navigation#replaceState) | ||
|
||
## :rocket: Version | ||
|
||
This rule was introduced in eslint-plugin-svelte v2.36.0-next.9 | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/no-navigation-without-resolve.ts) | ||
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/no-navigation-without-resolve.ts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.