Skip to content

Replace window references with globalThis in game.js#2

Open
sonarqube-agent[bot] wants to merge 1 commit into
devfrom
remediate-dev-20260616-153149-14949579
Open

Replace window references with globalThis in game.js#2
sonarqube-agent[bot] wants to merge 1 commit into
devfrom
remediate-dev-20260616-153149-14949579

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR was created because a team member assigned these issues to the Remediation Agent.

Fixed two SonarQube static analysis warnings (javascript:S7764) by replacing window.prompt() and window.alert() with their globalThis equivalents. Using globalThis instead of window improves code portability across different JavaScript environments, including Node.js and browser contexts.

View Project in SonarCloud


Fixed Issues

javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: public/game.js:142

Why is this an issue?

globalThis is the standardized way to access the global object across all JavaScript environments. Before globalThis, developers had to use different global references depending on the environment:

What changed

Replaces window.prompt(...) with globalThis.prompt(...) at line 142 of public/game.js, fixing the static analysis warning that prefers globalThis over window for accessing the global object. This makes the code more portable across JavaScript environments.

--- a/public/game.js
+++ b/public/game.js
@@ -142,1 +142,1 @@ async function gameOver() {
-  const name = window.prompt("Game over. Enter your name for the highscore:", "Player") || "Player";
+  const name = globalThis.prompt("Game over. Enter your name for the highscore:", "Player") || "Player";
javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: public/game.js:476

Why is this an issue?

globalThis is the standardized way to access the global object across all JavaScript environments. Before globalThis, developers had to use different global references depending on the environment:

What changed

Replaces window.alert(...) with globalThis.alert(...) at line 476 of public/game.js, fixing the static analysis warning that prefers globalThis over window for accessing the global object. This makes the code more portable across JavaScript environments.

--- a/public/game.js
+++ b/public/game.js
@@ -476,1 +476,1 @@ async function uploadBackground(file) {
-    window.alert(body.error || "Upload failed");
+    globalThis.alert(body.error || "Upload failed");

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ7RDO5qEdyOuX9cXX5B for javascript:S7764 rule
- AZ7RDO5qEdyOuX9cXX47 for javascript:S7764 rule

Generated by SonarQube Agent (task: 3fe0e437-6a46-4b41-8510-f11aa1410b4f)
@sonarqube-agent

Copy link
Copy Markdown
Author

⚠️ This repository does not have a CODEOWNERS file. The PR has been created but has not been automatically assigned to any reviewer. To ensure PRs are reviewed promptly, consider adding a CODEOWNERS file to your repository.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant