-
-
Notifications
You must be signed in to change notification settings - Fork 763
fix(linter/plugins): set up global scope correctly #17293
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(linter/plugins): set up global scope correctly #17293
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Pull request overview
This PR overhauls the global scope setup for the linter by removing the patch to @typescript-eslint/scope-manager and implementing a programmatic approach to manage global variables based on configuration. Instead of always using "esnext" globals, the system now creates globals according to env and globals from the config, and properly sets the writable property.
Key changes:
- Removed the patch file for
@typescript-eslint/scope-managerand updated dependency references to use the unpatched version - Implemented new
addGlobals()function in scope.ts that creates global variables from config and resolves references, replicating ESLint's behavior - Updated test case handling to build globals based on
ecmaVersionandsourceType, matching ESLint's preset behavior
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Removes the patchedDependencies section that referenced the @typescript-eslint/scope-manager patch |
| pnpm-lock.yaml | Updates dependency snapshots to use the unpatched @typescript-eslint/scope-manager version |
| patches/@typescript-eslint__scope-manager.patch | Complete removal of the patch file that modified ImplicitLibVariable behavior |
| apps/oxlint/src-js/plugins/scope.ts | Major refactor adding addGlobals() and createGlobalVariable() functions to programmatically set up global scope with variables from env/globals config, and resolve references |
| apps/oxlint/conformance/src/rule_tester.ts | Adds logic to build globals from ESLint presets based on ecmaVersion/sourceType, with helper functions getGlobals(), getGlobalsForEcmaVersion(), and addGlobalsFromPreset() |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ba840df to
61868e3
Compare
f7d734f to
5be63ec
Compare
61868e3 to
8dce152
Compare
5be63ec to
a54c849
Compare
Merge activity
|
Generate a file defining the vars that each environment (`env`) provides. This isn't used for anything yet, but it will be in next PR #17293. Vars for each environment are stored in this form: ```js { readonly: ["var1", "var2", "var3"], writable: ["var4", "var5"], } ``` instead of the more obvious: ```js { var1: false, var2: false, var3: false, var4: true, var5: true, } ``` ...because it's shorter code when there's lots of vars (which there usually are), and iterating through arrays I assume is faster than iterating through properties of objects (which are essentially hash maps when they're large).
Overhaul how variables in the global scope are set up. * Create globals according to `env` and `globals` from config - previously we always used a standard "esnext" set. * Remove the patch to `@typescript-eslint/scope-manager`. Instead do what ESLint does and patch up the global scope programmatically after TS-ESLint has produced the scope tree. * Set `writable` property for global variables according to config. This still isn't quite correct. There are many subtleties to this and I haven't got to the bottom of it all. But this PR fixes 500 conformance tests, so it's a large step in the right direction. I haven't added more tests in this PR, because I'm not actually sure what behavior is correct, and what still needs to be fixed. Once all the conformance tests related to globals (which is most of the remaining failing ones) are fixed, we'll have the full picture and can add more tests.
a54c849 to
e05115b
Compare
Overhaul how variables in the global scope are set up. * Create globals according to `env` and `globals` from config - previously we always used a standard "esnext" set. * Remove the patch to `@typescript-eslint/scope-manager`. Instead do what ESLint does and patch up the global scope programmatically after TS-ESLint has produced the scope tree. * Set `writable` property for global variables according to config. This still isn't quite correct. There are many subtleties to this and I haven't got to the bottom of it all. But this PR fixes 500 conformance tests, so it's a large step in the right direction. I haven't added more tests in this PR, because I'm not actually sure what behavior is correct, and what still needs to be fixed. Once all the conformance tests related to globals (which is most of the remaining failing ones) are fixed, we'll have the full picture and can add more tests.
e05115b to
7eaa660
Compare

Overhaul how variables in the global scope are set up.
envandglobalsfrom config - previously we always used a standard "esnext" set.@typescript-eslint/scope-manager. Instead do what ESLint does and patch up the global scope programmatically after TS-ESLint has produced the scope tree.writableproperty for global variables according to config.This still isn't quite correct. There are many subtleties to this and I haven't got to the bottom of it all. But this PR fixes 500 conformance tests, so it's a large step in the right direction.
I haven't added more tests in this PR, because I'm not actually sure what behavior is correct, and what still needs to be fixed. Once all the conformance tests related to globals (which is most of the remaining failing ones) are fixed, we'll have the full picture and can add more tests.