Skip to content

Commit 3ee1ae9

Browse files
committed
fix crash if declaration is in another file
1 parent f7032d9 commit 3ee1ae9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-unused-props.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,18 @@ function reportUnusedProp(
219219
const declaration = prop.getDeclarations()?.[0];
220220
if (declaration == null) return;
221221

222-
const node = services.tsNodeToESTreeNodeMap.get(declaration);
223-
const keyNode = node.type === T.TSPropertySignature
224-
? node.key
225-
: node;
222+
const declarationNode = services.tsNodeToESTreeNodeMap.get(declaration);
223+
224+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
225+
if (declarationNode == null) return; // is undefined if declaration is in a different file
226+
227+
const nodeToReport = declarationNode.type === T.TSPropertySignature
228+
? declarationNode.key
229+
: declarationNode;
226230

227231
context.report({
228232
messageId: "noUnusedProps",
229-
node: keyNode,
233+
node: nodeToReport,
230234
data: { name: prop.name },
231235
});
232236
}

0 commit comments

Comments
 (0)