diff --git a/packages/eslint-plugin/src/rules/no-deprecated.ts b/packages/eslint-plugin/src/rules/no-deprecated.ts index b39fb0609d35..7fb966a249b0 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated.ts @@ -94,10 +94,13 @@ export default createRule({ case AST_NODE_TYPES.Property: // foo in "const { foo } = bar" will be processed twice, as parent.key // and parent.value. The second is treated as a declaration. - return ( - (parent.shorthand && parent.value === node) || - parent.parent.type === AST_NODE_TYPES.ObjectExpression - ); + if (parent.shorthand && parent.value === node) { + return parent.parent.type === AST_NODE_TYPES.ObjectPattern; + } + if (parent.value === node) { + return false; + } + return parent.parent.type === AST_NODE_TYPES.ObjectExpression; case AST_NODE_TYPES.AssignmentPattern: // foo in "const { foo = "" } = bar" will be processed twice, as parent.parent.key @@ -306,9 +309,11 @@ export default createRule({ node.parent.type === AST_NODE_TYPES.Property && node.type !== AST_NODE_TYPES.Super ) { - return getJsDocDeprecation( - services.getTypeAtLocation(node.parent.parent).getProperty(node.name), - ); + const property = services + .getTypeAtLocation(node.parent.parent) + .getProperty(node.name); + const symbol = services.getSymbolAtLocation(node); + return getJsDocDeprecation(property) ?? getJsDocDeprecation(symbol); } return searchForDeprecationInAliasesChain( services.getSymbolAtLocation(node), diff --git a/packages/eslint-plugin/tests/rules/no-deprecated.test.ts b/packages/eslint-plugin/tests/rules/no-deprecated.test.ts index 8bbbe83a0837..39f3947891ef 100644 --- a/packages/eslint-plugin/tests/rules/no-deprecated.test.ts +++ b/packages/eslint-plugin/tests/rules/no-deprecated.test.ts @@ -681,6 +681,36 @@ ruleTester.run('no-deprecated', rule, { }, ], }, + { + code: ` + /** @deprecated */ + declare const test: string; + const myObj = { + prop: test, + deep: { + prop: test, + }, + }; + `, + errors: [ + { + column: 17, + data: { name: 'test' }, + endColumn: 21, + endLine: 5, + line: 5, + messageId: 'deprecated', + }, + { + column: 19, + data: { name: 'test' }, + endColumn: 23, + endLine: 7, + line: 7, + messageId: 'deprecated', + }, + ], + }, { code: ` /** @deprecated */ const a = { b: 1 };