Skip to content

Commit fb790dc

Browse files
authored
fix(eslint-plugin): [no-deprecated] report usage of deprecated private identifiers (#10844)
* check private variables for being deprecated * report the node name correctly
1 parent 5d503b9 commit fb790dc

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Diff for: packages/eslint-plugin/src/rules/no-deprecated.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type IdentifierLike =
1818
| TSESTree.Identifier
1919
| TSESTree.JSXIdentifier
20+
| TSESTree.PrivateIdentifier
2021
| TSESTree.Super;
2122

2223
type MessageIds = 'deprecated' | 'deprecatedWithReason';
@@ -377,7 +378,7 @@ export default createRule<Options, MessageIds>({
377378
return;
378379
}
379380

380-
const name = node.type === AST_NODE_TYPES.Super ? 'super' : node.name;
381+
const name = getReportedNodeName(node);
381382

382383
context.report({
383384
...(reason
@@ -400,7 +401,20 @@ export default createRule<Options, MessageIds>({
400401
checkIdentifier(node);
401402
}
402403
},
404+
PrivateIdentifier: checkIdentifier,
403405
Super: checkIdentifier,
404406
};
405407
},
406408
});
409+
410+
function getReportedNodeName(node: IdentifierLike): string {
411+
if (node.type === AST_NODE_TYPES.Super) {
412+
return 'super';
413+
}
414+
415+
if (node.type === AST_NODE_TYPES.PrivateIdentifier) {
416+
return `#${node.name}`;
417+
}
418+
419+
return node.name;
420+
}

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

+31
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ exists('/foo');
363363
declare const test: string;
364364
const bar = { test };
365365
`,
366+
`
367+
class A {
368+
#b = () => {};
369+
370+
c() {
371+
this.#b();
372+
}
373+
}
374+
`,
366375
],
367376
invalid: [
368377
{
@@ -2862,5 +2871,27 @@ class B extends A {
28622871
},
28632872
],
28642873
},
2874+
{
2875+
code: `
2876+
class A {
2877+
/** @deprecated */
2878+
#b = () => {};
2879+
2880+
c() {
2881+
this.#b();
2882+
}
2883+
}
2884+
`,
2885+
errors: [
2886+
{
2887+
column: 18,
2888+
data: { name: '#b' },
2889+
endColumn: 20,
2890+
endLine: 7,
2891+
line: 7,
2892+
messageId: 'deprecated',
2893+
},
2894+
],
2895+
},
28652896
],
28662897
});

0 commit comments

Comments
 (0)