-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(scope-manager): reconcile type-value distinction for implicit globals across libs #11715
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
Conversation
|
Thanks for the PR, @lilnasy! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many -t lint |
❌ Failed | 3m 21s | View ↗ |
nx test eslint-plugin --coverage=false |
✅ Succeeded | 5m 23s | View ↗ |
nx run-many -t typecheck |
✅ Succeeded | 1m 59s | View ↗ |
nx test eslint-plugin-internal --coverage=false |
✅ Succeeded | 12s | View ↗ |
nx test typescript-estree --coverage=false |
✅ Succeeded | 2s | View ↗ |
nx run integration-tests:test |
✅ Succeeded | 4s | View ↗ |
nx run types:build |
✅ Succeeded | 5s | View ↗ |
nx run generate-configs |
✅ Succeeded | 7s | View ↗ |
Additional runs (29) |
✅ Succeeded | ... | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-11-18 19:27:48 UTC
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11715 +/- ##
=======================================
Coverage 90.55% 90.55%
=======================================
Files 522 522
Lines 53063 53073 +10
Branches 8838 8842 +4
=======================================
+ Hits 48049 48059 +10
- Misses 4999 5000 +1
+ Partials 15 14 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
bradzacher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of mutating the variable here -- could we instead do it higher.
eg:
In the GlobalScope class (which calls ScopeBase.defineVariable):
typescript-eslint/packages/scope-manager/src/scope/GlobalScope.ts
Lines 68 to 79 in ea2ee6b
| public defineImplicitVariable( | |
| name: string, | |
| options: ImplicitLibVariableOptions, | |
| ): void { | |
| this.defineVariable( | |
| new ImplicitLibVariable(this, name, options), | |
| this.set, | |
| this.variables, | |
| null, | |
| null, | |
| ); | |
| } |
Or in the Referencer class (which calls GlobalScope.defineImplicitVariable):
typescript-eslint/packages/scope-manager/src/referencer/Referencer.ts
Lines 72 to 75 in ea2ee6b
| // This loop is guaranteed to see each included lib exactly once | |
| for (const [name, variable] of lib.variables) { | |
| globalScope.defineImplicitVariable(name, variable); | |
| } |
I think the latter would be better as we could pre-aggregate the variable definitions to deduplicate and merge them before even calling defineImplicitVariable.
|
@bradzacher I'm thinking it would be even better to go one level higher. The first year-wise occurrence of the globals I glimpsed at seems to always be |
|
I have a branch where I flatten the lib references at codegen time instead of at runtime, fixing the bug right there. It increases the package size a little but reduces I can move forward with whichever approach maintainers prefer. |
- Part of #14827 - Fixes the bug noticed in a review in #14890 (comment) - Originally reported as typescript-eslint/typescript-eslint#11714 - Originally fixed in typescript-eslint/typescript-eslint#11715 - Patching in oxlint because neither the bug nor the fix has been reviewed in the `typescript-eslint` org.
|
I believe the behaviour that we will need to add as part of the eslint v10 upgrades will provide you the behaviour you want. This behaviour will resolve all references to globals as part of the analysis rather than leaving them all open. |
|
@bradzacher so just confirming, is there any change we should make here? Is #11714 a no-op/wontfix given the upcoming ESLint v10 changes? Linking for visibility: #11762 tracks updating scope-manager for compatibility with ESLint v10. |
I agree.
@JoshuaKGoldberg I think that depends on what you meant in the comment here: #11762 (comment). Could you clarify? Can |
|
We haven't looked deeply into it yet, but I really hope so. Dropping support for v8 and v9 would be a breaking change that we're not ready to release a new major version for anytime soon. |
|
Well technically by being compatible with v10 we're also compatible with v8/v9 - cos eslint will just have nothing to do. |
|
Thanks, I thought that might be the case. Fixing this as part of ESLint 10 compat seems appropriate. Oxlint will be able to remove the patch we made to |
) - Part of oxc-project#14827 - Fixes the bug noticed in a review in oxc-project#14890 (comment) - Originally reported as typescript-eslint/typescript-eslint#11714 - Originally fixed in typescript-eslint/typescript-eslint#11715 - Patching in oxlint because neither the bug nor the fix has been reviewed in the `typescript-eslint` org.

PR Checklist
Overview
To fix the issue, implicit variables are mutated as the global scope is being populated.
I admittedly did not spend much time thinking of a proper solution. Though it was tricky to pinpoint, the fix is simple. I imagine the "correct" location for the fix is a matter of maintainer preference.
Direct commits from maintainers welcome.