Skip to content

Commit 60355cc

Browse files
committed
fix(no-unused-props): handle alias props name properly
1 parent 3308b87 commit 60355cc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Diff for: .changeset/fifty-jeans-thank.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix(no-unused-props): handle alias props name properly

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,22 @@ export default createRule('no-unused-props', {
185185
function getUsedPropertyNamesFromPattern(pattern: TSESTree.ObjectPattern): Set<string> {
186186
const usedProps = new Set<string>();
187187
for (const prop of pattern.properties) {
188-
if (prop.type === 'Property' && prop.key.type === 'Identifier') {
189-
usedProps.add(prop.key.name);
188+
if (prop.type === 'Property') {
189+
if (prop.key.type === 'Identifier') {
190+
usedProps.add(prop.key.name);
191+
} else if (
192+
prop.key.type === 'Literal' &&
193+
typeof prop.key.value === 'string' &&
194+
prop.value.type === 'Identifier'
195+
) {
196+
usedProps.add(prop.key.value);
197+
}
190198
} else if (prop.type === 'RestElement') {
191199
// If there's a rest element, all properties are potentially used
192200
return new Set();
193201
}
194202
}
203+
195204
return usedProps;
196205
}
197206

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script lang="ts">
2+
type Props = {
3+
test: string;
4+
'aria-label'?: string;
5+
};
6+
7+
const { test, 'aria-label': ariaLabel }: Props = $props();
8+
</script>
9+
10+
<h1>{test}</h1>
11+
<div aria-label={ariaLabel}>svelte/no-unused-props does not always respect aliases</div>

0 commit comments

Comments
 (0)