diff --git a/src/rules/deprecation.ts b/src/rules/deprecation.ts index 94a7b70..288bd78 100644 --- a/src/rules/deprecation.ts +++ b/src/rules/deprecation.ts @@ -49,32 +49,35 @@ export default createRule({ create(context) { const services = ESLintUtils.getParserServices(context); - return { - Identifier: (id: TSESTree.Identifier) => { - const insideImportExport = context - .getAncestors() - .some(anc => anc.type.includes('Import')); - if ( - insideImportExport || - (id.type === 'Identifier' && isDeclaration(id, context)) - ) { - // Don't consider deprecations if inside import/export. - // Also, the spot where something is declared is never deprecated. - return; - } + const rule = (id: TSESTree.Identifier | TSESTree.JSXIdentifier) => { + const insideImportExport = context + .getAncestors() + .some(anc => anc.type.includes('Import')); + if ( + insideImportExport || + ((id.type === 'Identifier' || id.type === 'JSXIdentifier') && + isDeclaration(id, context)) + ) { + // Don't consider deprecations if inside import/export. + // Also, the spot where something is declared is never deprecated. + return; + } - const deprecation = getDeprecation(id, services, context); - if (deprecation) { - context.report({ - node: id, - messageId: 'deprecated', - data: { - name: id.name, - reason: deprecation.reason, - }, - }); - } - }, + const deprecation = getDeprecation(id, services, context); + if (deprecation) { + context.report({ + node: id, + messageId: 'deprecated', + data: { + name: id.name, + reason: deprecation.reason, + }, + }); + } + }; + return { + Identifier: rule, + JSXIdentifier: rule, }; }, }); @@ -89,7 +92,7 @@ function getParent(context: TSESLint.RuleContext) { let lastProcessedDuplicateName: string | undefined; function isDeclaration( - id: TSESTree.Identifier, + id: TSESTree.Identifier | TSESTree.JSXIdentifier, context: TSESLint.RuleContext, ) { const parent = getParent(context); @@ -128,7 +131,7 @@ function isDeclaration( case 'ArrayPattern': // `const [foo, bar] = baz` // Array destructuring is truly a declaration on the left side // (even if there's reassignment) - return parent.elements.includes(id); + return id.type === 'Identifier' && parent.elements.includes(id); case 'Property': // no for ObjectExpression: `const foo = { bar: baz }` @@ -172,7 +175,7 @@ function isDeclaration( } function getDeprecation( - id: TSESTree.Identifier, + id: TSESTree.Identifier | TSESTree.JSXIdentifier, services: RequiredParserServices, context: TSESLint.RuleContext, ) { @@ -205,7 +208,7 @@ function getDeprecation( } function getSymbol( - id: TSESTree.Identifier, + id: TSESTree.Identifier | TSESTree.JSXIdentifier, services: RequiredParserServices, tc: ts.TypeChecker, ) { @@ -268,6 +271,8 @@ function isCallExpression( return node.callee === callee; } else if (node.type === 'TaggedTemplateExpression') { return node.tag === callee; + } else if (node.type === 'JSXOpeningElement') { + return node.name === callee; } } return false;