Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Dec 23, 2025

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.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-bug Category - Bug labels Dec 23, 2025
Copy link
Member Author

overlookmotel commented Dec 23, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review December 23, 2025 02:13
Copilot AI review requested due to automatic review settings December 23, 2025 02:13
Copy link
Contributor

Copilot AI left a 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-manager and 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 ecmaVersion and sourceType, 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.

@overlookmotel overlookmotel force-pushed the om/12-22-refactor_linter_plugins_add_environments_definitions branch from ba840df to 61868e3 Compare December 23, 2025 02:27
@overlookmotel overlookmotel force-pushed the om/12-22-fix_linter_plugins_set_up_global_scope_correctly branch from f7d734f to 5be63ec Compare December 23, 2025 02:27
@graphite-app graphite-app bot force-pushed the om/12-22-refactor_linter_plugins_add_environments_definitions branch from 61868e3 to 8dce152 Compare December 23, 2025 10:47
@graphite-app graphite-app bot force-pushed the om/12-22-fix_linter_plugins_set_up_global_scope_correctly branch from 5be63ec to a54c849 Compare December 23, 2025 10:47
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Dec 23, 2025
Copy link
Contributor

camc314 commented Dec 23, 2025

Merge activity

@graphite-app graphite-app bot changed the base branch from om/12-22-refactor_linter_plugins_add_environments_definitions to graphite-base/17293 December 23, 2025 10:54
graphite-app bot pushed a commit that referenced this pull request Dec 23, 2025
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).
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 23, 2025
@graphite-app graphite-app bot changed the base branch from graphite-base/17293 to main December 23, 2025 11:00
@github-actions github-actions bot added the A-ast-tools Area - AST tools label Dec 23, 2025
graphite-app bot pushed a commit that referenced this pull request Dec 23, 2025
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.
@graphite-app graphite-app bot force-pushed the om/12-22-fix_linter_plugins_set_up_global_scope_correctly branch from a54c849 to e05115b Compare December 23, 2025 11:01
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.
@graphite-app graphite-app bot force-pushed the om/12-22-fix_linter_plugins_set_up_global_scope_correctly branch from e05115b to 7eaa660 Compare December 23, 2025 11:05
@graphite-app graphite-app bot merged commit 7eaa660 into main Dec 23, 2025
19 checks passed
@graphite-app graphite-app bot deleted the om/12-22-fix_linter_plugins_set_up_global_scope_correctly branch December 23, 2025 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants