Skip to content

fix: replace window with globalThis in swagger-initializer.js#14

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260331-035335-a6986539
Open

fix: replace window with globalThis in swagger-initializer.js#14
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260331-035335-a6986539

Conversation

@sonarqube-agent

Copy link
Copy Markdown

Replaces window.location.search with globalThis.location.search to prefer the standardized global object accessor over the browser-specific window global. This improves code portability across different JavaScript environments such as browsers, Node.js, and Web Workers, addressing the SonarQube javascript:S7764 code smell.

View Project in SonarCloud


Fixed Issues

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

Location: swagger/src/main/resources/com/webcohesion/enunciate/modules/swagger/swagger-initializer.js:3

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.location.search with globalThis.location.search on line 3 of swagger-initializer.js, directly fixing the code smell that flags the use of the environment-specific window global instead of the standardized globalThis for accessing the global object. This makes the code more portable across different JavaScript environments (browser, Node.js, Web Workers) as recommended by the prefer-global-this rule.

--- a/swagger/src/main/resources/com/webcohesion/enunciate/modules/swagger/swagger-initializer.js
+++ b/swagger/src/main/resources/com/webcohesion/enunciate/modules/swagger/swagger-initializer.js
@@ -3,1 +3,1 @@ window.onload = function() {
-  let url = window.location.search.match(/url=([^&]+)/);
+  let url = globalThis.location.search.match(/url=([^&]+)/);

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZpHzODgBLcwshDrw6nS for javascript:S7764 rule

Generated by SonarQube Agent (task: 4431c35d-4850-4a38-b940-d629cddec7e0)
@sonarqubecloud

Copy link
Copy Markdown

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