Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy 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 fromall 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 deletionspackages/eslint-plugin/src/rules/no-deprecated.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionpackages/eslint-plugin/tests/rules/no-deprecated.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp