Skip to content

Commit e94b59a

Browse files
authored
fix: resolve false positives on nested objects in no-unused-props rule (#1128)
1 parent 22634dd commit e94b59a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.changeset/fuzzy-ads-join.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: resolve false positives on nested objects in `no-unused-props` rule

packages/eslint-plugin-svelte/src/rules/no-unused-props.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export default createRule('no-unused-props', {
319319
.filter((v): v is TSESTree.Identifier => v.type === 'Identifier');
320320
for (const identifier of identifiers) {
321321
const paths = getUsedNestedPropertyNames(identifier);
322-
usedPaths.push(...paths);
322+
usedPaths.push(...paths.map((path) => [identifier.name, ...path]));
323323
}
324324
} else if (node.id.type === 'Identifier') {
325325
usedPaths = getUsedNestedPropertyNames(node.id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script lang="ts">
2+
// fix: https://github.com/sveltejs/eslint-plugin-svelte/issues/1028#issuecomment-2728101827
3+
type Prop = {
4+
value: string;
5+
value2: string;
6+
};
7+
8+
interface Props {
9+
myObjectProp: Prop;
10+
}
11+
12+
const { myObjectProp }: Props = $props();
13+
</script>
14+
15+
<p>{myObjectProp.value} {myObjectProp.value2}</p>

0 commit comments

Comments
 (0)