Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/eslint-plugin/src/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
30 changes: 30 additions & 0 deletions packages/eslint-plugin/tests/rules/no-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Loading