Skip to content
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

Generalized no-goto-without-base into no-navigation-without-base #900

Merged
merged 12 commits into from
Dec 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(no-navigation-without-base): added test for pushState, replaceSt…
…ate and links
marekdedic committed Dec 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 2a03e8860ad94245557265f19cd87e76ce53e2e5
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ These rules relate to SvelteKit and its best Practices.

| Rule ID | Description | |
|:--------|:------------|:---|
| [svelte/no-navigation-without-base](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-navigation-without-base/) | disallow using goto() without the base path | |
| [svelte/no-navigation-without-base](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-navigation-without-base/) | disallow using navigation (links, goto, pushState, replaceState) without the base path | |

## Experimental

6 changes: 3 additions & 3 deletions docs/rules.md
Original file line number Diff line number Diff line change
@@ -109,9 +109,9 @@ These rules extend the rules provided by ESLint itself, or other plugins to work

These rules relate to SvelteKit and its best Practices.

| Rule ID | Description | |
| :------------------------------------------------------------------------- | :------------------------------------------ | :-- |
| [svelte/no-navigation-without-base](./rules/no-navigation-without-base.md) | disallow using goto() without the base path | |
| Rule ID | Description | |
| :------------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | :-- |
| [svelte/no-navigation-without-base](./rules/no-navigation-without-base.md) | disallow using navigation (links, goto, pushState, replaceState) without the base path | |

## Experimental

4 changes: 2 additions & 2 deletions docs/rules/no-navigation-without-base.md
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@
pageClass: 'rule-details'
sidebarDepth: 0
title: 'svelte/no-navigation-without-base'
description: 'disallow using goto() without the base path'
description: 'disallow using navigation (links, goto, pushState, replaceState) without the base path'
since: 'v2.36.0-next.9'
---

# svelte/no-navigation-without-base

> disallow using goto() without the base path
> disallow using navigation (links, goto, pushState, replaceState) without the base path

## :book: Rule Details

2 changes: 1 addition & 1 deletion packages/eslint-plugin-svelte/src/rule-types.ts
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ export interface RuleOptions {
*/
'svelte/no-inspect'?: Linter.RuleEntry<[]>
/**
* disallow using goto() without the base path
* disallow using navigation (links, goto, pushState, replaceState) without the base path
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-navigation-without-base/
*/
'svelte/no-navigation-without-base'?: Linter.RuleEntry<[]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- message: Found a link with a url that isn't prefixed with the base path.
line: 5
column: 9
suggestions: null
- message: Found a link with a url that isn't prefixed with the base path.
line: 6
column: 9
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { base } from '$app/paths';
</script>

<a href={'/foo/' + base}>Click me!</a>
<a href={`/foo/${base}`}>Click me!</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- message: Found a link with a url that isn't prefixed with the base path.
line: 1
column: 10
suggestions: null
- message: Found a link with a url that isn't prefixed with the base path.
line: 2
column: 9
suggestions: null
- message: Found a link with a url that isn't prefixed with the base path.
line: 3
column: 9
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="/foo">Click me!</a>
<a href={'/foo'}>Click me!</a>
<a href={'/' + 'foo'}>Click me!</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- message: Found a pushState() call with a url that isn't prefixed with the base path.
line: 4
column: 8
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { pushState as alias } from '$app/navigation';

alias('/foo');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- message: Found a pushState() call with a url that isn't prefixed with the base path.
line: 5
column: 12
suggestions: null
- message: Found a pushState() call with a url that isn't prefixed with the base path.
line: 6
column: 12
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { base } from '$app/paths';
import { pushState } from '$app/navigation';

pushState('/foo/' + base);
pushState(`/foo/${base}`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- message: Found a pushState() call with a url that isn't prefixed with the base path.
line: 4
column: 12
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { pushState } from '$app/navigation';

pushState('/foo');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- message: Found a replaceState() call with a url that isn't prefixed with the
base path.
line: 4
column: 8
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { replaceState as alias } from '$app/navigation';

alias('/foo');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- message: Found a replaceState() call with a url that isn't prefixed with the
base path.
line: 5
column: 15
suggestions: null
- message: Found a replaceState() call with a url that isn't prefixed with the
base path.
line: 6
column: 15
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { base } from '$app/paths';
import { replaceState } from '$app/navigation';

replaceState('/foo/' + base);
replaceState(`/foo/${base}`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- message: Found a replaceState() call with a url that isn't prefixed with the
base path.
line: 4
column: 15
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { replaceState } from '$app/navigation';

replaceState('/foo');
</script>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
const protocol = 'https';
</script>

<a href="http://svelte.dev">Click me!</a>
<a href="https://svelte.dev">Click me!</a>
<a href={'http://svelte.dev'}>Click me!</a>
<a href={'https://svelte.dev'}>Click me!</a>
<a href={'http://svelte' + '.dev'}>Click me!</a>
<a href={'https://svelte' + '.dev'}>Click me!</a>
<a href={'http' + '://svelte.dev'}>Click me!</a>
<a href={'https' + '://svelte.dev'}>Click me!</a>
<a href={`${protocol}://svelte.dev`}>Click me!</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { base as alias } from '$app/paths';
</script>

<a href={alias + '/foo/'}>Click me!</a>;
<a href={`${alias}/foo/`}>Click me!</a>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { base } from '$app/paths';
</script>

<a href={base + '/foo/'}>Click me!</a>
<a href={`${base}/foo/`}>Click me!</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { base as alias } from '$app/paths';
import { pushState } from '$app/navigation';

// eslint-disable-next-line prefer-template -- Testing both variants
pushState(alias + '/foo/');
pushState(`${alias}/foo/`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { base } from '$app/paths';
import { pushState } from '$app/navigation';

// eslint-disable-next-line prefer-template -- Testing both variants
pushState(base + '/foo/');
pushState(`${base}/foo/`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { pushState } from '$app/navigation';

pushState('');
pushState(``);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { base as alias } from '$app/paths';
import { replaceState } from '$app/navigation';

// eslint-disable-next-line prefer-template -- Testing both variants
replaceState(alias + '/foo/');
replaceState(`${alias}/foo/`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { base } from '$app/paths';
import { replaceState } from '$app/navigation';

// eslint-disable-next-line prefer-template -- Testing both variants
replaceState(base + '/foo/');
replaceState(`${base}/foo/`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
import { replaceState } from '$app/navigation';

replaceState('');
replaceState(``);
</script>