8000 fix(eslint-plugin): [no-deprecated] doesn't report on shorthand prope… · 43081j/typescript-eslint@63b2d3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 63b2d3e

Browse files
authored
fix(eslint-plugin): [no-deprecated] doesn't report on shorthand property in an object expression (typescript-eslint#10550)
* fix: doesn't report on shorthand property * test: add test * test: add valid test
1 parent 4dbf48b commit 63b2d3e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,17 @@ export default createRule({
312312
const property = services
313313
.getTypeAtLocation(node.parent.parent)
314314
.getProperty(node.name);
315-
const symbol = services.getSymbolAtLocation(node);
316-
return getJsDocDeprecation(property) ?? getJsDocDeprecation(symbol);
315+
const propertySymbol = services.getSymbolAtLocation(node);
316+
const valueSymbol = checker.getShorthandAssignmentValueSymbol(
317+
propertySymbol?.valueDeclaration,
318+
);
319+
return (
320+
getJsDocDeprecation(property) ??
321+
getJsDocDeprecation(propertySymbol) ??
322+
getJsDocDeprecation(valueSymbol)
323+
);
317324
}
325+
318326
return searchForDeprecationInAliasesChain(
319327
services.getSymbolAtLocation(node),
320328
true,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ ruleTester.run('no-deprecated', rule, {
312312
}
313313
<foo bar={1} />;
314314
`,
315+
`
316+
declare const test: string;
317+
const bar = { test };
318+
`,
315319
],
316320
invalid: [
317321
{
@@ -711,6 +715,25 @@ ruleTester.run('no-deprecated', rule, {
711715
},
712716
],
713717
},
718+
{
719+
code: `
720+
/** @deprecated */
721+
declare const test: string;
722+
const bar = {
723+
test,
724+
};
725+
`,
726+
errors: [
727+
{
728+
column: 11,
729+
data: { name: 'test' },
730+
endColumn: 15,
731+
endLine: 5,
732+
line: 5,
733+
messageId: 'deprecated',
734+
},
735+
],
736+
},
714737
{
715738
code: `
716739
/** @deprecated */ const a = { b: 1 };

0 commit comments

Comments
 (0)
0