fix: resolve 5 SonarQube code quality issues in addOnto.js#30
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve 5 SonarQube code quality issues in addOnto.js#30sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZmd8Pu0uPWA3VN6PKN3 for javascript:S7764 rule - AZmd8Pu0uPWA3VN6PKN4 for javascript:S7781 rule - AZmd8Pu0uPWA3VN6PKN5 for javascript:S7765 rule - AZmd8Pu0uPWA3VN6PKN6 for javascript:S7781 rule - AZmd8Pu0uPWA3VN6PKN7 for javascript:S7765 rule Generated by SonarQube Agent (task: fa0ba987-0628-4bbd-bea3-2faf9ea69c9a)
Contributor
Author
|
|
|
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.



This PR fixes 5 SonarQube violations in addOnto.js by replacing deprecated patterns with modern JavaScript standards: using globalThis instead of window, String#replaceAll() instead of regex-based replace(), and String#includes() instead of indexOf() comparisons. These changes improve code clarity, safety, and maintainability while adhering to current best practices.
View Project in SonarCloud
Fixed Issues
javascript:S7764 - Prefer `globalThis` over `window`. • MINOR • View issue
Location:
content/assets/js/addOnto.js:158Why is this an issue?
globalThisis the standardized way to access the global object across all JavaScript environments. BeforeglobalThis, developers had to use different global references depending on the environment:What changed
This hunk replaces
windowwithglobalThisin the scroll event handler$(window).scroll(...). The static analysis flagged the use ofwindowto access the global object, recommendingglobalThisinstead as the standardized, environment-portable way to reference the global object (ES2020). This change directly resolves that warning.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
content/assets/js/addOnto.js:224Why is this an issue?
The
String#replaceAll()method was introduced in ES2021 to provide a clearer and safer way to replace all occurrences of a pattern in a string.What changed
This hunk replaces
searchTerm.replace(/ /g, ...)withsearchTerm.replaceAll(' ', ...). The static analysis flagged the use ofString#replace()with a global regex that matches a simple literal space character, recommendingString#replaceAll()with a string literal instead for clarity and safety. This change directly resolves that warning at line 224.javascript:S7765 - Use `.includes()`, rather than `.indexOf()`, when checking for existence. • MINOR • View issue
Location:
content/assets/js/addOnto.js:227Why is this an issue?
Using
.indexOf()or.lastIndexOf()with comparison operators like!== -1or>= 0to check if an element exists is less readable and semantic than using.includes(). The intent is not immediately clear - you need to understand that-1means "not found" and remember the comparison logic.What changed
This hunk replaces
.toLowerCase().indexOf(...) >= 0with.toLowerCase().includes(...). The static analysis flagged the use of.indexOf()with a>= 0comparison to check for element existence, recommending.includes()instead as it more clearly expresses the intent of an existence check. This change directly resolves that warning at line 227.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
content/assets/js/addOnto.js:267Why is this an issue?
The
String#replaceAll()method was introduced in ES2021 to provide a clearer and safer way to replace all occurrences of a pattern in a string.What changed
This hunk replaces
searchTerm.replace(/ /g, ...)withsearchTerm.replaceAll(' ', ...). The static analysis flagged the use ofString#replace()with a global regex matching a simple literal space, recommendingString#replaceAll()with a string literal for better readability and safety. This change directly resolves that warning at line 267.javascript:S7765 - Use `.includes()`, rather than `.indexOf()`, when checking for existence. • MINOR • View issue
Location:
content/assets/js/addOnto.js:270Why is this an issue?
Using
.indexOf()or.lastIndexOf()with comparison operators like!== -1or>= 0to check if an element exists is less readable and semantic than using.includes(). The intent is not immediately clear - you need to understand that-1means "not found" and remember the comparison logic.What changed
This hunk replaces
.toLowerCase().indexOf(...) >= 0with.toLowerCase().includes(...). The static analysis flagged the use of.indexOf()with a>= 0comparison for existence checking, recommending.includes()as a more readable and semantic alternative. This change directly resolves that warning at line 270.SonarQube Remediation Agent uses AI. Check for mistakes.