8000 fix(eslint-plugin): [no-deprecated] not reporting usages of deprecate… · 43081j/typescript-eslint@6c75493 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c75493

Browse files
authored
fix(eslint-plugin): [no-deprecated] not reporting usages of deprecated declared constants as object value (typescript-eslint#10498)
* fix: no-deprecated * test: add test * refactor: delete unnecessary function
1 parent 6fb5c3e commit 6c75493

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

packages/eslint-plugin/src/rules/no-deprecated.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ export default createRule({
9494
case AST_NODE_TYPES.Property:
9595
// foo in "const { foo } = bar" will be processed twice, as parent.key
9696
// and parent.value. The second is treated as a declaration.
97-
return (
98-
(parent.shorthand && parent.value === node) ||
99-
parent.parent.type === AST_NODE_TYPES.ObjectExpression
100-
);
97+
if (parent.shorthand && parent.value === node) {
98+
return parent.parent.type === AST_NODE_TYPES.ObjectPattern;
99+
}
100+
if (parent.value === node) {
101+
return false;
102+
}
103+
return parent.parent.type === AST_NODE_TYPES.ObjectExpression;
101104

102105
case AST_NODE_TYPES.AssignmentPattern:
103106
// foo in "const { foo = "" } = bar" will be processed twice, as parent.parent.key
@@ -306,9 +309,11 @@ export default createRule({
306309
node.parent.type === AST_NODE_TYPES.Property &&
307310
node.type !== AST_NODE_TYPES.Super
308311
) {
309-
return getJsDocDeprecation(
310-
services.getTypeAtLocation(node.parent.parent).getProperty(node.name),
311-
);
312+
const property = services
313+
.getTypeAtLocation(node.parent.parent)
314+
.getProperty(node.name);
315+
const symbol = services.getSymbolAtLocation(node);
316+
return getJsDocDeprecation(property) ?? getJsDocDeprecation(symbol);
312317
}
313318
return searchForDeprecationInAliasesChain(
314319
services.getSymbolAtLocation(node),

packages/eslint-plugin/tests/rules/no-deprecated.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,36 @@ ruleTester.run('no-deprecated', rule, {
681681
},
682682
],
683683
},
684+
{
685+
code: `
686+
/** @deprecated */
687+
declare const test: string;
688+
const myObj = {
689+
prop: test,
690+
deep: {
691+
prop: test,
692+
},
693+
};
694+
`,
695+
errors: [
696+
{
697+
column: 17,
698+
data: { name: 'test' },
699+
endColumn: 21,
700+
endLine: 5,
701+
line: 5,
702+
messageId: 'deprecated',
703+
},
704+
{
705+
column: 19,
706+
data: { name: 'test' },
707+
endColumn: 23,
708+
endLine: 7,
709+
line: 7,
710+
messageId: 'deprecated',
711+
},
712+
],
713+
},
684714
{
685715
code: `
686716
/** @deprecated */ const a = { b: 1 };

0 commit comments

Comments
 (0)
0