-
-
Notifications
You must be signed in to change notification settings - Fork 735
feat(linter/plugins): allow JS plugins to access globals
#16512
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
base: main
Are you sure you want to change the base?
feat(linter/plugins): allow JS plugins to access globals
#16512
Conversation
CodSpeed Performance ReportMerging #16512 will not alter performanceComparing Summary
Footnotes
|
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.
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.
|
@overlookmotel Makes sense. I'll address the review comments tonight and add todo comments for performance. |
globals by serializing globals for every fileglobals
53416c8 to
d8a94c0
Compare
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 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
ExternalLinterLintFileCbtype 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.
|
Addressed all review comments. CI is failing because spell check flaked. |
Future work
envfield. Implement support if not currently supported.globalsfor all files only once at the start of the lint run.AI Usage