fix: replace var with let in swagger-initializer.js#15
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: replace var with let in swagger-initializer.js#15sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZZmtins2HDYqP_XyoK8 for javascript:S3504 rule Generated by SonarQube Agent (task: 9f16b745-9838-4a54-b286-05a0273e0165)
SonarQube reviewer guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




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. • CRITICAL • View issue
Location:
swagger/src/main/resources/com/webcohesion/enunciate/modules/swagger/swagger-initializer.js:11Why is this an issue?
Variables declared with
varare function-scoped, meaning they are accessible within the entire function in which they are defined. If a variable is declared usingvaroutside 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'.
SonarQube Remediation Agent uses AI. Check for mistakes.