Skip to content
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

fix(eslint-plugin): report deprecations used in default export #10330

Merged
merged 1 commit into from
Nov 16, 2024
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
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/no-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export default createRule({
while (true) {
switch (current.type) {
case AST_NODE_TYPES.ExportAllDeclaration:
case AST_NODE_TYPES.ExportDefaultDeclaration:
case AST_NODE_TYPES.ExportNamedDeclaration:
case AST_NODE_TYPES.ImportDeclaration:
return true;
Expand Down
37 changes: 37 additions & 0 deletions packages/eslint-plugin/tests/rules/no-deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ ruleTester.run('no-deprecated', rule, {

a('b');
`,
`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a fine test of overloaded function signature logic! I'm happy for us to keep it around, but I think for the sake of this issue we should also have a test purely for the default export usage that's as simple as

function notDeprecated() {
  return {};
}

export default notDeprecated();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added additional valid test 🙂

function a(value: 'b' | undefined): void;
/** @deprecated */
function a(value: 'c' | undefined): void;
function a(value: string | undefined): void {
// ...
}

export default a('b');
`,
`
function notDeprecated(): object {
return {};
}

export default notDeprecated();
`,
`
import { deprecatedFunctionWithOverloads } from './deprecated';

Expand Down Expand Up @@ -2463,5 +2480,25 @@ ruleTester.run('no-deprecated', rule, {
},
],
},
{
code: `
/** @deprecated */
function a(): object {
return {};
}

export default a();
`,
errors: [
{
column: 24,
data: { name: 'a' },
endColumn: 25,
endLine: 7,
line: 7,
messageId: 'deprecated',
},
],
},
],
});
Loading