diff --git a/packages/eslint-plugin/src/rules/no-deprecated.ts b/packages/eslint-plugin/src/rules/no-deprecated.ts index 8833c05b4c82..94d7a5ed7262 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated.ts @@ -17,6 +17,7 @@ import { type IdentifierLike = | TSESTree.Identifier | TSESTree.JSXIdentifier + | TSESTree.PrivateIdentifier | TSESTree.Super; type MessageIds = 'deprecated' | 'deprecatedWithReason'; @@ -377,7 +378,7 @@ export default createRule({ return; } - const name = node.type === AST_NODE_TYPES.Super ? 'super' : node.name; + const name = getReportedNodeName(node); context.report({ ...(reason @@ -400,7 +401,20 @@ export default createRule({ checkIdentifier(node); } }, + PrivateIdentifier: checkIdentifier, Super: checkIdentifier, }; }, }); + +function getReportedNodeName(node: IdentifierLike): string { + if (node.type === AST_NODE_TYPES.Super) { + return 'super'; + } + + if (node.type === AST_NODE_TYPES.PrivateIdentifier) { + return `#${node.name}`; + } + + return node.name; +} diff --git a/packages/eslint-plugin/tests/rules/no-deprecated.test.ts b/packages/eslint-plugin/tests/rules/no-deprecated.test.ts index 1d5745fe0b56..6469c0fe5c23 100644 --- a/packages/eslint-plugin/tests/rules/no-deprecated.test.ts +++ b/packages/eslint-plugin/tests/rules/no-deprecated.test.ts @@ -363,6 +363,15 @@ exists('/foo'); declare const test: string; const bar = { test }; `, + ` + class A { + #b = () => {}; + + c() { + this.#b(); + } + } + `, ], invalid: [ { @@ -2862,5 +2871,27 @@ class B extends A { }, ], }, + { + code: ` + class A { + /** @deprecated */ + #b = () => {}; + + c() { + this.#b(); + } + } + `, + errors: [ + { + column: 18, + data: { name: '#b' }, + endColumn: 20, + endLine: 7, + line: 7, + messageId: 'deprecated', + }, + ], + }, ], });