Skip to content

Commit 21046f5

Browse files
committed
test(no-navigation-without-base): added test for pushState, replaceState and links
1 parent e6949ea commit 21046f5

32 files changed

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

packages/eslint-plugin-svelte/tests/fixtures/rules/no-navigation-without-base/valid/absolute-uri01-input.svelte

Lines changed: 0 additions & 6 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<a href="http://svelte.dev">Click me!</a>
2+
<a href="https://svelte.dev">Click me!</a>
3+
<a href={'http://svelte.dev'}>Click me!</a>
4+
<a href={'https://svelte.dev'}>Click me!</a>
5+
<a href={'http://svelte' + '.dev'}>Click me!</a>
6+
<a href={'https://svelte' + '.dev'}>Click me!</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { base as alias } from '$app/paths';
3+
</script>
4+
5+
<a href={alias + '/foo/'}>Click me!</a>;
6+
<a href={`${alias}/foo/`}>Click me!</a>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { base } from '$app/paths';
3+
</script>
4+
5+
<a href={base + '/foo/'}>Click me!</a>
6+
<a href={`${base}/foo/`}>Click me!</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { base as alias } from '$app/paths';
3+
import { pushState } from '$app/navigation';
4+
5+
// eslint-disable-next-line prefer-template -- Testing both variants
6+
pushState(alias + '/foo/');
7+
pushState(`${alias}/foo/`);
8+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { base } from '$app/paths';
3+
import { pushState } from '$app/navigation';
4+
5+
// eslint-disable-next-line prefer-template -- Testing both variants
6+
pushState(base + '/foo/');
7+
pushState(`${base}/foo/`);
8+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { pushState } from '$app/navigation';
3+
4+
pushState('');
5+
pushState(``);
6+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { base as alias } from '$app/paths';
3+
import { replaceState } from '$app/navigation';
4+
5+
// eslint-disable-next-line prefer-template -- Testing both variants
6+
replaceState(alias + '/foo/');
7+
replaceState(`${alias}/foo/`);
8+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { base } from '$app/paths';
3+
import { replaceState } from '$app/navigation';
4+
5+
// eslint-disable-next-line prefer-template -- Testing both variants
6+
replaceState(base + '/foo/');
7+
replaceState(`${base}/foo/`);
8+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
import { replaceState } from '$app/navigation';
3+
4+
replaceState('');
5+
replaceState(``);
6+
</script>

0 commit comments

Comments
 (0)