Repository: sveltejs/eslint-plugin-svelte
Pull request #1100 (2025-02-26 12:11:02)

fix: handle `<script module>` in `valid-prop-names-in-kit-pages` rule
close: https://github.com/sveltejs/eslint-plugin-svelte/issues/1098

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: e3b04693346eff545390928fd6f9de39eb5b9ebd

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name                 | Type  |
| -------------------- | ----- |
| eslint-plugin-svelte | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/sveltejs/eslint-plugin-svelte/new/fix/valid-prop-names-in-kit-pages?filename=.changeset/smart-peas-sip.md&value=---%0A%22eslint-plugin-svelte%22%3A%20patch%0A---%0A%0Afix%3A%20handle%20%60%3Cscript%20module%3E%60%20in%20%60valid-prop-names-in-kit-pages%60%20rule%0A)


github-actions[bot]: <!-- posted by pkg.pr.new-comment.mjs -->

## Try the Instant Preview in Online Playground

[ESLint Online Playground](https://eslint-online-playground.netlify.app/?overrideDeps=%7B%22eslint-plugin-svelte%22%3A%22https%3A%2F%2Fpkg.pr.new%2Feslint-plugin-svelte%401100%22%7D#eslint-plugin-svelte%20with%20typescript)

## Install the Instant Preview to Your Local

```
npm i https://pkg.pr.new/eslint-plugin-svelte@1100
```

## Published Instant Preview Packages:

- eslint-plugin-svelte: https://pkg.pr.new/eslint-plugin-svelte@1100

[View Commit](https://github.com/sveltejs/eslint-plugin-svelte/commit/e3b04693346eff545390928fd6f9de39eb5b9ebd)

Patch:
diff --git a/.changeset/vast-clouds-accept.md b/.changeset/vast-clouds-accept.md
new file mode 100644
index 0000000..e6d7948
--- /dev/null
+++ b/.changeset/vast-clouds-accept.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-svelte': patch
+---
+
+fix: handle `<script module>` in `valid-prop-names-in-kit-pages` rule
diff --git a/packages/eslint-plugin-svelte/src/rules/valid-prop-names-in-kit-pages.ts b/packages/eslint-plugin-svelte/src/rules/valid-prop-names-in-kit-pages.ts
index 95cbe49..f6b21dd 100644
--- a/packages/eslint-plugin-svelte/src/rules/valid-prop-names-in-kit-pages.ts
+++ b/packages/eslint-plugin-svelte/src/rules/valid-prop-names-in-kit-pages.ts
@@ -28,6 +28,23 @@ function checkProp(
 	}
 }
 
+function isModuleScript(node: AST.SvelteAttribute) {
+	// <script context="module">
+	if (
+		node.key.name === 'context' &&
+		node.value.some((v) => v.type === 'SvelteLiteral' && v.value === 'module')
+	) {
+		return true;
+	}
+
+	// <script module>
+	if (node.key.name === 'module' && node.value.length === 0) {
+		return true;
+	}
+
+	return false;
+}
+
 export default createRule('valid-prop-names-in-kit-pages', {
 	meta: {
 		docs: {
@@ -54,12 +71,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
 			// <script>
 			'Program > SvelteScriptElement > SvelteStartTag': (node: AST.SvelteStartTag) => {
 				// except for <script context="module">
-				isScript = !node.attributes.some(
-					(a) =>
-						a.type === 'SvelteAttribute' &&
-						a.key.name === 'context' &&
-						a.value.some((v) => v.type === 'SvelteLiteral' && v.value === 'module')
-				);
+				isScript = !node.attributes.some((a) => a.type === 'SvelteAttribute' && isModuleScript(a));
 			},
 
 			// </script>


Test patch:
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-1/+page.svelte
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002/+page.svelte
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-1/+page.svelte
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-1/_config.json
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002/_config.json
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-1/_config.json
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-2/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-2/+page.svelte
new file mode 100644
index 0000000..eb7393f
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-2/+page.svelte
@@ -0,0 +1,8 @@
+<script module>
+	export let data;
+	export let errors;
+	export let foo;
+	export let bar;
+</script>
+
+{data}, {errors}, {foo}, {bar}
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-2/_config.json
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003/_config.json
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test002-2/_config.json
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-1/+page.svelte
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003/+page.svelte
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-1/+page.svelte
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-1/_config.json
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004/_config.json
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-1/_config.json
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/+page.svelte
new file mode 100644
index 0000000..7eaf286
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/+page.svelte
@@ -0,0 +1,5 @@
+<script module>
+	export const { data, errors } = { data: {}, errors: {} };
+</script>
+
+{data}, {errors}
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/_config.json
new file mode 100644
index 0000000..9861188
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test003-2/_config.json
@@ -0,0 +1,11 @@
+{
+	"settings": {
+		"svelte": {
+			"kit": {
+				"files": {
+					"routes": "tests/fixtures"
+				}
+			}
+		}
+	}
+}
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-1/+page.svelte
similarity index 100%
rename from packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004/+page.svelte
rename to packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-1/+page.svelte
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-1/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-1/_config.json
new file mode 100644
index 0000000..9861188
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-1/_config.json
@@ -0,0 +1,11 @@
+{
+	"settings": {
+		"svelte": {
+			"kit": {
+				"files": {
+					"routes": "tests/fixtures"
+				}
+			}
+		}
+	}
+}
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/+page.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/+page.svelte
new file mode 100644
index 0000000..c28b010
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/+page.svelte
@@ -0,0 +1,5 @@
+<script module>
+	export const { data2: data, errors2: errors } = { data2: {}, errors2: {} };
+</script>
+
+{data}, {errors}
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/_config.json b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/_config.json
new file mode 100644
index 0000000..9861188
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/valid-prop-names-in-kit-pages/valid/test004-2/_config.json
@@ -0,0 +1,11 @@
+{
+	"settings": {
+		"svelte": {
+			"kit": {
+				"files": {
+					"routes": "tests/fixtures"
+				}
+			}
+		}
+	}
+}