Skip to content

fix: replace var with let in swagger-initializer.js#15

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260331-035332-97b5d49d
Open

fix: replace var with let in swagger-initializer.js#15
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260331-035332-97b5d49d

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Replace 'var' with 'let' for the 'baseUrl' variable declaration to comply with SonarQube rule S3504. This change improves code quality by using block-level scoping instead of function-level scoping, preventing potential hoisting-related bugs and following modern JavaScript best practices.

View Project in SonarCloud


Fixed Issues

javascript:S3504 - Unexpected var, use let or const instead. • CRITICALView issue

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

Why is this an issue?

Variables declared with var are function-scoped, meaning they are accessible within the entire function in which they are defined. If a variable is declared using var outside of any function, it becomes a global variable and is accessible throughout the entire JavaScript program.

What changed

Replaces 'var' with 'let' for the 'baseUrl' variable declaration. The static analysis rule flags the use of 'var' because it has function-level scoping and hoisting behavior that can lead to unexpected bugs. Since 'baseUrl' is reassigned later in the code (e.g., trimming the hash or query string), 'let' is the appropriate modern replacement, providing block-level scoping and avoiding the pitfalls of 'var'.

--- 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
@@ -11,1 +11,1 @@ window.onload = function() {
-    var baseUrl = document.location.href;
+    let baseUrl = document.location.href;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZZmtins2HDYqP_XyoK8 for javascript:S3504 rule

Generated by SonarQube Agent (task: 9f16b745-9838-4a54-b286-05a0273e0165)
@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