Skip to content

Conversation

@lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Dec 4, 2025

Future work

  • Add test for globals from the env field. Implement support if not currently supported.
  • Optimization: we want to serialize globals for all files only once at the start of the lint run.

AI Usage

  • This PR was drafted by Claude Sonnet 4.5 in Plan + Agent mode, then manually reviewed and iterated on.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins labels Dec 4, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 4, 2025

CodSpeed Performance Report

Merging #16512 will not alter performance

Comparing lilnasy:globals-quick-dirty-and-inefficient (3a44ac0) with main (40b0134)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (e24aabd) during the generation of this report, so 40b0134 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you've said this is just an experiment, but I think we should merge it!

Yes, it's inefficient to serialize globals for every file (ditto settings). But at least it works! Much better than just not supporting it at all, which is what we have now.

A few comments below - none major.


We also support an env option in config: https://oxc.rs/docs/guide/usage/linter/config.html#configuration-file-format

I'm not sure globals from env already get merged into OxlintGlobals on Rust side, in which case it'll work already after this PR.

If so, we should add a test for that. If not, we should add support for env (simplest way would be to just apply env to OxlintGlobals on Rust side, before serializing to JSON). Either way, I suggest leaving that to a follow-up PR.

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 6, 2025

@overlookmotel Makes sense. I'll address the review comments tonight and add todo comments for performance.

@lilnasy lilnasy changed the title experiment(linter/plugins): allow JS plugins to access globals by serializing globals for every file feat(linter/plugins): allow JS plugins to access globals Dec 6, 2025
@lilnasy lilnasy force-pushed the globals-quick-dirty-and-inefficient branch from 53416c8 to d8a94c0 Compare December 6, 2025 18:18
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Dec 6, 2025
@lilnasy lilnasy marked this pull request as ready for review December 6, 2025 18:58
@lilnasy lilnasy requested a review from camc314 as a code owner December 6, 2025 18:58
Copilot AI review requested due to automatic review settings December 6, 2025 18:58
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 enables JavaScript plugins to access the globals configuration by passing serialized globals from Rust to JavaScript for each file during linting. The implementation follows the existing pattern used for settings, serializing the globals once per file to support folder-level overrides.

Key Changes:

  • Added globals serialization in Rust and deserialization in TypeScript with lazy initialization
  • Extended the ExternalLinterLintFileCb type signature to include globals JSON parameter
  • Implemented globals conversion from "writeable" to "writable" for ESLint compatibility in JavaScript

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/oxc_linter/src/lib.rs Serializes globals to JSON and passes to external linter callback
crates/oxc_linter/src/external_linter.rs Updates type signature to accept globals JSON parameter
crates/oxc_linter/src/context/host.rs Adds getter method to expose globals from config
crates/oxc_linter/src/config/globals.rs Adds TODO comment about adding serde rename for ESLint compatibility
apps/oxlint/src/run.rs Updates type signature for globals parameter in JS callback
apps/oxlint/src/js_plugins/external_linter.rs Passes globals JSON to JavaScript lint function
apps/oxlint/src-js/plugins/lint.ts Accepts and processes globals JSON parameter, with incorrect import extension
apps/oxlint/src-js/plugins/globals.ts New module implementing globals deserialization with "writeable" to "writable" conversion, contains incorrect import extension
apps/oxlint/src-js/plugins/context.ts Exposes globals via languageOptions with lazy initialization
apps/oxlint/src-js/plugins/config.ts Updates TODO to include globals setup
apps/oxlint/src-js/package/rule_tester.ts Adds empty globals JSON parameter for testing
apps/oxlint/src-js/cli.ts Forwards globals JSON parameter to lint function
apps/oxlint/src-js/bindings.d.ts Updates type definition to include globals parameter
apps/oxlint/test/fixtures/globals/* Test fixtures verifying globals functionality with base and override configurations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lilnasy
Copy link
Contributor Author

lilnasy commented Dec 6, 2025

Addressed all review comments. CI is failing because spell check flaked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants