Skip to content

Commit a1fe4ac

Browse files
authored
[feat] Support snapshot to valid-prop-names-in-kit-pages rule (#366)
1 parent 01b2d01 commit a1fe4ac

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.changeset/yellow-games-double.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-svelte": minor
3+
---
4+
5+
Support `snapshot` to `valid-prop-names-in-kit-pages` rule

docs/rules/valid-prop-names-in-kit-pages.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ At SvelteKit v1.0.0-next.405, instead of having multiple props corresponding to
3636
/** ✓ GOOD */
3737
export let data
3838
export let errors
39+
export let form
40+
export let snapshot
3941
// export let { data, errors } = { data: {}, errors: {} }
4042
4143
/** ✗ BAD */

src/rules/valid-prop-names-in-kit-pages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { TSESTree } from "@typescript-eslint/types"
33
import { createRule } from "../utils"
44
import { isKitPageComponent } from "../utils/svelte-kit"
55

6-
const EXPECTED_PROP_NAMES = ["data", "errors", "form"]
6+
const EXPECTED_PROP_NAMES = ["data", "errors", "form", "snapshot"]
77

88
export default createRule("valid-prop-names-in-kit-pages", {
99
meta: {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
<script>
22
export let data
33
export let errors
4+
export let form
5+
6+
let comment = ""
7+
8+
export const snapshot = {
9+
capture: () => comment,
10+
restore: (value) => (comment = value),
11+
}
412
</script>
513

614
{data}, {errors}
15+
16+
{#if form?.success}
17+
<p>Successfully logged in! Welcome back, {data.user.name}</p>
18+
{/if}
19+
20+
<form method="POST">
21+
<textarea bind:value={comment} />
22+
<button>Post comment</button>
23+
</form>

0 commit comments

Comments
 (0)