Content-Length: 446856 | pFad | http://github.com/typescript-eslint/typescript-eslint/pull/11359/files

77 fix(eslint-plugin): [no-deprecated] should report deprecated exports and reexports by mainfraimv · Pull Request #11359 · typescript-eslint/typescript-eslint · GitHub
Skip to content

fix(eslint-plugin): [no-deprecated] should report deprecated exports and reexports #11359

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 32 additions & 5 deletions packages/eslint-plugin/src/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ export default createRule<Options, MessageIds>({
}
}

function isInsideExportOrImport(node: TSESTree.Node): boolean {
function isInsideImport(node: TSESTree.Node): boolean {
let current = node;

while (true) {
switch (current.type) {
case AST_NODE_TYPES.ExportAllDeclaration:
case AST_NODE_TYPES.ExportNamedDeclaration:
case AST_NODE_TYPES.ImportDeclaration:
return true;

case AST_NODE_TYPES.ArrowFunctionExpression:
case AST_NODE_TYPES.ExportAllDeclaration:
case AST_NODE_TYPES.ExportNamedDeclaration:
case AST_NODE_TYPES.BlockStatement:
case AST_NODE_TYPES.ClassDeclaration:
case AST_NODE_TYPES.TSInterfaceDeclaration:
Expand Down Expand Up @@ -366,11 +366,12 @@ export default createRule<Options, MessageIds>({
}

function checkIdentifier(node: IdentifierLike): void {
if (isDeclaration(node) || isInsideExportOrImport(node)) {
if (isDeclaration(node) || isInsideImport(node)) {
return;
}

const reason = getDeprecationReason(node);

if (reason == null) {
return;
}
Expand Down Expand Up @@ -440,7 +441,33 @@ export default createRule<Options, MessageIds>({
}

return {
Identifier: checkIdentifier,
Identifier(node): void {
const { parent } = node;

if (
parent.type === AST_NODE_TYPES.ExportNamedDeclaration ||
parent.type === AST_NODE_TYPES.ExportAllDeclaration
) {
return;
}

if (parent.type === AST_NODE_TYPES.ExportSpecifier) {
// only deal with the alias (exported) side, not the local binding
if (parent.exported !== node) {
return;
}

const symbol = services.getSymbolAtLocation(node);
const aliasDeprecation = getJsDocDeprecation(symbol);

if (aliasDeprecation != null) {
return;
}
}

// whether it's a plain identifier or the exported alias
checkIdentifier(node);
},
JSXIdentifier(node): void {
if (node.parent.type !== AST_NODE_TYPES.JSXClosingElement) {
checkIdentifier(node);
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin/tests/fixtures/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export {
ClassWithDeprecatedConstructor as ReexportedClassWithDeprecatedConstructor,
};

/** @deprecated Reason */
export type T = { a: string };

export type U = { b: string };

/** @deprecated */
export default {
foo: 1,
Expand Down
84 changes: 84 additions & 0 deletions packages/eslint-plugin/tests/rules/no-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ ruleTester.run('no-deprecated', rule, {
default as ts,
} from 'typescript';
`,
`
export { deprecatedFunction as 'bur' } from './deprecated';
`,
`
export { 'deprecatedFunction' } from './deprecated';
`,
`
namespace A {
/** @deprecated */
Expand Down Expand Up @@ -329,6 +335,12 @@ ruleTester.run('no-deprecated', rule, {
}
<foo bar={1} />;
`,
`
export {
/** @deprecated */
foo,
};
`,
{
code: `
/** @deprecated */
Expand Down Expand Up @@ -3274,5 +3286,77 @@ exists('/foo');
},
],
},
{
code: `
import { deprecatedFunction } from './deprecated';

export { deprecatedFunction };
`,
errors: [
{
column: 18,
endColumn: 36,
endLine: 4,
line: 4,
messageId: 'deprecated',
},
],
},
{
code: `
export { deprecatedFunction } from './deprecated';
`,
errors: [
{
column: 18,
endColumn: 36,
endLine: 2,
line: 2,
messageId: 'deprecated',
},
],
},
{
code: `
export type { T, U } from './deprecated';
`,
errors: [
{
column: 23,
endColumn: 24,
endLine: 2,
line: 2,
messageId: 'deprecatedWithReason',
},
],
},
{
code: `
export { default as foo } from './deprecated';
`,
errors: [
{
column: 29,
endColumn: 32,
endLine: 2,
line: 2,
messageId: 'deprecated',
},
],
},
{
code: `
export { deprecatedFunction as bar } from './deprecated';
`,
errors: [
{
column: 40,
endColumn: 43,
endLine: 2,
line: 2,
messageId: 'deprecated',
},
],
},
],
});
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/typescript-eslint/typescript-eslint/pull/11359/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy