Skip to content

Commit bc2cbf4

Browse files
committed
fix: correct detection of externally defined types in no-unused-props rule
1 parent bea4945 commit bc2cbf4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changeset/plain-chairs-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: correct detection of externally defined types in `no-unused-props` rule

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ export default createRule('no-unused-props', {
8080
return shouldIgnore(typeStr) || (symbolName ? shouldIgnore(symbolName) : false);
8181
}
8282

83-
function isExternalType(type: ts.Type): boolean {
84-
const symbol = type.getSymbol();
83+
function isInternalType(type: ts.Type): boolean {
84+
const symbol = type.getSymbol() ?? type.aliasSymbol;
8585
if (!symbol) return false;
8686

8787
const declarations = symbol.getDeclarations();
8888
if (!declarations || declarations.length === 0) return false;
8989

90-
const sourceFile = declarations[0].getSourceFile();
91-
return sourceFile.fileName !== fileName;
90+
const isSameFile = declarations.every((decl) => decl.getSourceFile().fileName === fileName);
91+
if (!isSameFile) return false;
92+
93+
const baseTypes = type.getBaseTypes() ?? [];
94+
return baseTypes.every((baseType) => isInternalType(baseType));
9295
}
9396

9497
/**
@@ -200,7 +203,7 @@ export default createRule('no-unused-props', {
200203
if (checkedTypes.has(typeStr)) return;
201204
checkedTypes.add(typeStr);
202205
if (shouldIgnoreType(type)) return;
203-
if (!checkImportedTypes && isExternalType(type)) return;
206+
if (!checkImportedTypes && !isInternalType(type)) return;
204207

205208
const properties = typeChecker.getPropertiesOfType(type);
206209
const baseTypes = type.getBaseTypes();

0 commit comments

Comments
 (0)