Repository: sveltejs/eslint-plugin-svelte
Pull request #1128 (2025-03-17 08:44:44)

fix: resolve false positives on nested objects in `no-unused-props` rule
close: https://github.com/sveltejs/eslint-plugin-svelte/pull/1061#issuecomment-2728592702
close: https://github.com/sveltejs/eslint-plugin-svelte/issues/1028#issuecomment-2728101827

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

Latest commit: 252a9c9242870fbf6af1b49be7d0cf1f641db573

**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/no-unused-props?filename=.changeset/strange-vans-explain.md&value=---%0A%22eslint-plugin-svelte%22%3A%20patch%0A---%0A%0Afix%3A%20resolve%20false%20positives%20on%20nested%20objects%20in%20%60no-unused-props%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%401128%22%7D#eslint-plugin-svelte%20with%20typescript)

## Install the Instant Preview to Your Local

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

## Published Instant Preview Packages:

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

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

Patch:
diff --git a/.changeset/fuzzy-ads-join.md b/.changeset/fuzzy-ads-join.md
new file mode 100644
index 0000000..5af5eb1
--- /dev/null
+++ b/.changeset/fuzzy-ads-join.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-svelte': patch
+---
+
+fix: resolve false positives on nested objects in `no-unused-props` rule
diff --git a/packages/eslint-plugin-svelte/src/rules/no-unused-props.ts b/packages/eslint-plugin-svelte/src/rules/no-unused-props.ts
index 1588f3b..0d057b3 100644
--- a/packages/eslint-plugin-svelte/src/rules/no-unused-props.ts
+++ b/packages/eslint-plugin-svelte/src/rules/no-unused-props.ts
@@ -319,7 +319,7 @@ export default createRule('no-unused-props', {
 						.filter((v): v is TSESTree.Identifier => v.type === 'Identifier');
 					for (const identifier of identifiers) {
 						const paths = getUsedNestedPropertyNames(identifier);
-						usedPaths.push(...paths);
+						usedPaths.push(...paths.map((path) => [identifier.name, ...path]));
 					}
 				} else if (node.id.type === 'Identifier') {
 					usedPaths = getUsedNestedPropertyNames(node.id);


Test patch:
diff --git a/packages/eslint-plugin-svelte/tests/fixtures/rules/no-unused-props/valid/ts-basic-input.svelte b/packages/eslint-plugin-svelte/tests/fixtures/rules/no-unused-props/valid/ts-basic-input.svelte
new file mode 100644
index 0000000..d2c509f
--- /dev/null
+++ b/packages/eslint-plugin-svelte/tests/fixtures/rules/no-unused-props/valid/ts-basic-input.svelte
@@ -0,0 +1,15 @@
+<script lang="ts">
+	// fix: https://github.com/sveltejs/eslint-plugin-svelte/issues/1028#issuecomment-2728101827
+	type Prop = {
+		value: string;
+		value2: string;
+	};
+
+	interface Props {
+		myObjectProp: Prop;
+	}
+
+	const { myObjectProp }: Props = $props();
+</script>
+
+<p>{myObjectProp.value} {myObjectProp.value2}</p>