Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
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 havesearched for related issues and found none that matched my issue.
- I haveread 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 moduleforRoot
method returning aModuleWithProviders
configuration object, so as to bind the now deprecatedNGXS_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
- clone the repo
npm install
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 byts(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 theno-deprecated rule source for tag 8.24.0.
It fails ingetDeprecationReason
while considering thenode.parent.type
as a property.
When the variable is local / not imported, thegetJsDocDeprecation(propertySymbol)
call at line 353 succeeds.
It returnsundefined
when the variable is imported.
In the debugger, evaluatingsearchForDeprecationInAliasesChain
the same way as line 358 returns the right deprecation reason.
This seems related, as the comment abovesearchForDeprecationInAliasesChain
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.