Skip to content

fix: resolve 5 SonarQube code quality issues in addOnto.js#30

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260509-090159-8caf7965
Open

fix: resolve 5 SonarQube code quality issues in addOnto.js#30
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260509-090159-8caf7965

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

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`. • MINORView issue

Location: content/assets/js/addOnto.js:158

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

This hunk replaces window with globalThis in the scroll event handler $(window).scroll(...). The static analysis flagged the use of window to access the global object, recommending globalThis instead as the standardized, environment-portable way to reference the global object (ES2020). This change directly resolves that warning.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -158,1 +158,1 @@ $(document).ready(function(){
-         $(window).scroll(function () {
+         $(globalThis).scroll(function () {
javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINORView issue

Location: content/assets/js/addOnto.js:224

Why 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, ...) with searchTerm.replaceAll(' ', ...). The static analysis flagged the use of String#replace() with a global regex that matches a simple literal space character, recommending String#replaceAll() with a string literal instead for clarity and safety. This change directly resolves that warning at line 224.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -224,1 +224,1 @@ $(document).ready(function(){
-        var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
+        var searchSplit = searchTerm.replaceAll(' ', "'):containsi('")
javascript:S7765 - Use `.includes()`, rather than `.indexOf()`, when checking for existence. • MINORView issue

Location: content/assets/js/addOnto.js:227

Why is this an issue?

Using .indexOf() or .lastIndexOf() with comparison operators like !== -1 or >= 0 to check if an element exists is less readable and semantic than using .includes(). The intent is not immediately clear - you need to understand that -1 means "not found" and remember the comparison logic.

What changed

This hunk replaces .toLowerCase().indexOf(...) >= 0 with .toLowerCase().includes(...). The static analysis flagged the use of .indexOf() with a >= 0 comparison 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.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -227,1 +227,1 @@ $(document).ready(function(){
-            return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
+            return (elem.textContent || elem.innerText || '').toLowerCase().includes((match[3] || "").toLowerCase());
javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINORView issue

Location: content/assets/js/addOnto.js:267

Why 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, ...) with searchTerm.replaceAll(' ', ...). The static analysis flagged the use of String#replace() with a global regex matching a simple literal space, recommending String#replaceAll() with a string literal for better readability and safety. This change directly resolves that warning at line 267.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -267,1 +267,1 @@ $(document).ready(function(){
-        var searchSplit = searchTerm.replace(/ /g, "'):containsi('")
+        var searchSplit = searchTerm.replaceAll(' ', "'):containsi('")
javascript:S7765 - Use `.includes()`, rather than `.indexOf()`, when checking for existence. • MINORView issue

Location: content/assets/js/addOnto.js:270

Why is this an issue?

Using .indexOf() or .lastIndexOf() with comparison operators like !== -1 or >= 0 to check if an element exists is less readable and semantic than using .includes(). The intent is not immediately clear - you need to understand that -1 means "not found" and remember the comparison logic.

What changed

This hunk replaces .toLowerCase().indexOf(...) >= 0 with .toLowerCase().includes(...). The static analysis flagged the use of .indexOf() with a >= 0 comparison for existence checking, recommending .includes() as a more readable and semantic alternative. This change directly resolves that warning at line 270.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -270,1 +270,1 @@ $(document).ready(function(){
-            return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
+            return (elem.textContent || elem.innerText || '').toLowerCase().includes((match[3] || "").toLowerCase());

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


SonarQube Remediation Agent uses AI. Check for mistakes.

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)
@sonarqube-agent
Copy link
Copy Markdown
Contributor 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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

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