Skip to content

feat(biome_js_analyze): implement useGlobalThis#8928

Merged
dyc3 merged 10 commits intobiomejs:mainfrom
taga3s:implement-useGlobalThis
Feb 2, 2026
Merged

feat(biome_js_analyze): implement useGlobalThis#8928
dyc3 merged 10 commits intobiomejs:mainfrom
taga3s:implement-useGlobalThis

Conversation

@taga3s
Copy link
Contributor

@taga3s taga3s commented Feb 1, 2026

Summary

This PR adds useGlobalThis, ported from eslint-plugin-unicorn. It enforces the use of globalThis over window, self and global because globalThis is a standard way to access the global object which contributes to the portability of your code.

Test Plan

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

🦋 Changeset detected

Latest commit: a249c24

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Feb 1, 2026
@taga3s taga3s force-pushed the implement-useGlobalThis branch from b96ec3c to 5175c30 Compare February 1, 2026 10:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

Walkthrough

A new nursery lint rule useGlobalThis was added to the BiomeJS analyzer. The rule and its node union were implemented in Rust under crates/biome_js_analyze, accompanied by valid and invalid unit tests. An empty UseGlobalThisOptions struct was added to crates/biome_rule_options, and a changelog patch for the @biomejs/biome package was introduced. No existing public APIs were removed.

Suggested reviewers

  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(biome_js_analyze): implement useGlobalThis' clearly and concisely summarises the main change - implementing the new useGlobalThis linting rule.
Description check ✅ Passed The description is directly related to the changeset, detailing the rule implementation, its purpose (enforcing globalThis usage), the source (eslint-plugin-unicorn), and test coverage.
Linked Issues check ✅ Passed The PR successfully implements the useGlobalThis rule as requested in issue #8826, with proper rule logic, comprehensive test cases, and feature parity with the eslint source.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the useGlobalThis rule: rule implementation, options struct, test files, and changelog entry - no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 1, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing taga3s:implement-useGlobalThis (a249c24) with main (d876a38)

Summary

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks1

Footnotes

  1. 95 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.

@github-actions github-actions bot added the A-CLI Area: CLI label Feb 1, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/biome_js_analyze/src/lint/nursery/use_global_this.rs`:
- Around line 219-288: In check_expression, the JS_COMPUTED_MEMBER_ASSIGNMENT
and JS_COMPUTED_MEMBER_EXPRESSION branches currently treat any computed member
text as a literal property name; change them to only call
check_is_window_specific_api / check_is_web_worker_specific_api when the
computed member is actually a string literal by using as_static_value() (e.g.,
call member.as_static_value() or the crate helper to obtain a StaticValue and
verify it’s a string) before trimming and passing it to
check_is_window_specific_api; keep the existing fallback behavior (no exemption)
when as_static_value() is None so variables like window[innerWidth] are not
exempted.
🧹 Nitpick comments (1)
crates/biome_rule_options/src/use_global_this.rs (1)

1-6: Add a brief rustdoc for the options struct. Line 6 declares a public options type without a doc string; a one‑liner keeps generated docs consistent.

Suggested tweak
+/// Options for the `useGlobalThis` rule.
 pub struct UseGlobalThisOptions {}

As per coding guidelines, Use inline rustdoc documentation for rules, assists, and their options.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/biome_js_analyze/src/lint/nursery/use_global_this.rs`:
- Around line 307-315: The current check extracts the first argument's text via
first_arg.to_trimmed_text() without confirming it's a string literal, so
variables would be treated as string names; update the logic inside the
call_expr branch to first try to get a static string via
first_arg.as_static_value() (or equivalent API) and only if that returns
Some(string) then trim quotes and call is_window_specific_event(string); keep
the existing guards (EVENT_TARGET_METHODS, call_expr.arguments(), etc.) and
avoid calling to_trimmed_text() on non-literals so the event check only runs for
true string constants.
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/use_global_this.rs (1)

35-109: Consider sorting these arrays alphabetically for easier maintenance.

The API lists are comprehensive and well-documented with spec references. Sorting alphabetically would make it easier to check for duplicates and find specific entries during future updates.

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

A good first draft, i like it!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/biome_js_analyze/src/lint/nursery/use_global_this.rs`:
- Around line 324-338: The current logic lets non-literal event names fall
through and be treated as window-specific; change the branch that checks
EVENT_TARGET_METHODS so that when member_name.text() matches an event-target
method you explicitly handle two cases: if you successfully parse a string
literal (the existing chain ending with event.token_text_trimmed()) return
is_window_specific_event(&event), otherwise return false (do not fall through).
Keep the final "true" return for the other non-event-target window-specific API
checks. Reference symbols: EVENT_TARGET_METHODS, member_name.text(),
call_expr.arguments(), first_arg.as_js_string_literal_expression(),
event.token_text_trimmed(), and is_window_specific_event.

@taga3s
Copy link
Contributor Author

taga3s commented Feb 2, 2026

@dyc3 Thank you for your review! I have addressed your feedback. I would appreciate it if you could review again.

@taga3s taga3s requested a review from dyc3 February 2, 2026 10:35
Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Nice work!

@dyc3 dyc3 merged commit ccaeac4 into biomejs:main Feb 2, 2026
20 checks passed
@github-actions github-actions bot mentioned this pull request Feb 2, 2026
@taga3s taga3s deleted the implement-useGlobalThis branch February 3, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port prefer-global-this from eslint-plugin-unicorn

2 participants