Skip to content

feat(eslint-plugin): [no-deprecated] report on super call of deprecated constructor #10397

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
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
17 changes: 13 additions & 4 deletions packages/eslint-plugin/src/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import * as ts from 'typescript';

import { createRule, getParserServices, nullThrows } from '../util';

type IdentifierLike = TSESTree.Identifier | TSESTree.JSXIdentifier;
type IdentifierLike =
| TSESTree.Identifier
| TSESTree.JSXIdentifier
| TSESTree.Super;

export default createRule({
name: 'no-deprecated',
Expand Down Expand Up @@ -276,7 +279,10 @@ export default createRule({
if (callLikeNode) {
return getCallLikeDeprecation(callLikeNode);
}
if (node.parent.type === AST_NODE_TYPES.Property) {
if (
node.parent.type === AST_NODE_TYPES.Property &&
node.type !== AST_NODE_TYPES.Super
) {
return getJsDocDeprecation(
services.getTypeAtLocation(node.parent.parent).getProperty(node.name),
);
Expand All @@ -297,15 +303,17 @@ export default createRule({
return;
}

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

context.report({
...(reason
? {
messageId: 'deprecatedWithReason',
data: { name: node.name, reason },
data: { name, reason },
}
: {
messageId: 'deprecated',
data: { name: node.name },
data: { name },
}),
node,
});
Expand All @@ -318,6 +326,7 @@ export default createRule({
checkIdentifier(node);
}
},
Super: checkIdentifier,
};
},
});
52 changes: 51 additions & 1 deletion packages/eslint-plugin/tests/rules/no-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ ruleTester.run('no-deprecated', rule, {
code: `
/** @deprecated */
declare function decorator(constructor: Function);

@decorator
export class Foo {}
`,
Expand Down Expand Up @@ -2500,5 +2500,55 @@ ruleTester.run('no-deprecated', rule, {
},
],
},
{
code: `
class A {
/** @deprecated */
constructor() {}
}

class B extends A {
constructor() {
/** should report but does not */
super();
}
}
`,
errors: [
{
column: 5,
data: { name: 'super' },
endColumn: 10,
endLine: 10,
line: 10,
messageId: 'deprecated',
},
],
},
{
code: `
class A {
/** @deprecated test reason*/
constructor() {}
}

class B extends A {
constructor() {
/** should report but does not */
super();
}
}
`,
errors: [
{
column: 5,
data: { name: 'super', reason: 'test reason' },
endColumn: 10,
endLine: 10,
line: 10,
messageId: 'deprecatedWithReason',
},
],
},
],
});
Loading