Skip to content

fix(eslint-plugin): [no-deprecated] report usage of deprecated private identifiers #10844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
16 changes: 15 additions & 1 deletion packages/eslint-plugin/src/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type IdentifierLike =
| TSESTree.Identifier
| TSESTree.JSXIdentifier
| TSESTree.PrivateIdentifier
| TSESTree.Super;

type MessageIds = 'deprecated' | 'deprecatedWithReason';
Expand Down Expand Up @@ -377,7 +378,7 @@ export default createRule<Options, MessageIds>({
return;
}

const name = node.type === AST_NODE_TYPES.Super ? 'super' : node.name;
const name = getReportedNodeName(node);

context.report({
...(reason
Expand All @@ -400,7 +401,20 @@ export default createRule<Options, MessageIds>({
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;
}
31 changes: 31 additions & 0 deletions packages/eslint-plugin/tests/rules/no-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ exists('/foo');
declare const test: string;
const bar = { test };
`,
`
class A {
#b = () => {};

c() {
this.#b();
}
}
`,
],
invalid: [
{
Expand Down Expand Up @@ -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',
},
],
},
],
});
Loading