Skip to content

Bug: [no-deprecated] Deprecated imported variable used in an object not detected/reported #10828

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

Closed
4 tasks done
StephaneSeyvoz opened this issue Feb 13, 2025 · 1 comment · Fixed by #10998
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.

Comments

@StephaneSeyvoz
Copy link

StephaneSeyvoz commented Feb 13, 2025

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

When using an imported deprecated variable inside an object to assign it to a field, the usage is not detected/reported by the rule, both in CLI (npx eslint) and the VSCode ESLint extension.

When the variable is not imported, declared in the same file, the issue is reported correctly.
When using an intermediate variable, the issue is reported correctly.

The original case I was handling was in an Angular module forRoot method returning a ModuleWithProviders configuration object, so as to bind the now deprecated NGXS_PLUGINS injection token from the NGXS library (since v18.1.6) to an implementation service/provider.

Reproduction Repository Link

https://github.com/StephaneSeyvoz/typescript-eslint-no-deprecated

Repro Steps

  1. clone the repo
  2. npm install
  3. npx eslint or open in VSCode with the ESLint extension
src\main.ts
  18:18  error  `deprecatedVar` is deprecated. For some reason; Usually would be an Angular injection token        @typescript-eslint/no-deprecated  
  24:26  error  `deprecatedModuleVar` is deprecated. For some reason; Usually would be an Angular injection token  @typescript-eslint/no-deprecated  
  45:16  error  `deprecatedVar` is deprecated. For some reason; Usually would be an Angular injection token        @typescript-eslint/no-deprecated  
  52:24  error  `deprecatedModuleVar` is deprecated. For some reason; Usually would be an Angular injection token  @typescript-eslint/no-deprecated  

✖ 4 problems (4 errors, 0 warnings)

-> Lines 10 and 36 are not detected/reported
-> In VSCode, lines 10 and 36 are shown as deprecated by ts(6385), not ESLint

Versions

package version
@typescript-eslint/eslint-plugin 8.24.0
@typescript-eslint/parser 8.24.0
@typescript-eslint/scope-manager 8.24.0
@typescript-eslint/typescript-estree 8.24.0
@typescript-eslint/type-utils 8.24.0
@typescript-eslint/utils 8.24.0
TypeScript 5.7.3
ESLint 9.20.1
node 20.16.0

Quick self-analysis

I tried tracking the issue in the no-deprecated rule source for tag 8.24.0.
It fails in getDeprecationReason while considering the node.parent.type as a property.

When the variable is local / not imported, the getJsDocDeprecation(propertySymbol) call at line 353 succeeds.
It returns undefined when the variable is imported.

In the debugger, evaluating searchForDeprecationInAliasesChain the same way as line 358 returns the right deprecation reason.
This seems related, as the comment above searchForDeprecationInAliasesChain says:

// Deprecated jsdoc tags can be added on some symbol alias, e.g.
//
// export { /** @deprecated */ foo }
//
// When we import foo, its symbol is an alias of the exported foo (the one
// with the deprecated tag), which is itself an alias of the original foo.
// Therefore, we carefully go through the chain of aliases and check each
// immediate alias for deprecated tags

So I guess it's just about applying the right behaviour with imported properties.

Checking for duplicates

I found #10643, but:

  • it seems different since no import is used there,
  • the issue isn't here when the variable is local.

so I considered it was a different problem.

@StephaneSeyvoz StephaneSeyvoz added bug Something isn't working triage Waiting for team members to take a look labels Feb 13, 2025
@ronami
Copy link
Member

ronami commented Feb 15, 2025

This definitely seems like a bug to me.

The rule seems to report the following correctly:

/** @deprecated For some reason; Usually would be an Angular injection token */
export const deprecatedModuleVar = 'anything';

const test = {
  someField: deprecatedModuleVar,
};

But fails to report the same variable if it's re-exported from a different file:

import { deprecatedModuleVar } from './util';

const test = {
  someField: deprecatedModuleVar,
};

I think you're correct @StephaneSeyvoz, it seems like the rule doesn't use searchForDeprecationInAliasesChain for this case.

Thanks for reporting this 👍

@ronami ronami added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Feb 15, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 15, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.
Projects
None yet
2 participants