Skip to content

fix: resolve 5 SonarQube code quality issues#31

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260510-090215-98af1561
Open

fix: resolve 5 SonarQube code quality issues#31
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260510-090215-98af1561

Conversation

@sonarqube-agent
Copy link
Copy Markdown
Contributor

Removed commented-out code, fixed variable scope declaration, and replaced browser-specific window references with standardized globalThis to improve code maintainability and portability across JavaScript environments. These changes address code smells and bring the codebase into compliance with modern JavaScript best practices.

View Project in SonarCloud


Fixed Issues

javascript:S125 - Remove this commented out code. • MAJORView issue

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

Why is this an issue?

Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid.

What changed

This hunk removes the commented-out jQuery code //$("#terminologit-search-content-valueset-cld").attr("id","logical-definition-accordion-group"); at line 144 of addOnto.js, replacing it with blank lines. This directly addresses the code smell about commented-out code that should be removed, as it creates noise and distracts from actual executed code.

--- a/content/assets/js/addOnto.js
+++ b/content/assets/js/addOnto.js
@@ -144,1 +144,1 @@ $(document).ready(function(){
-        //$("#terminologit-search-content-valueset-cld").attr("id","logical-definition-accordion-group");
+
javascript:S2392 - Consider moving declaration of 'currentTabIndex' as it is referenced outside current binding context. • MAJORView issue

Location: content/assets/js/tabs.js:2

Why is this an issue?

The var statement declares variables that are function-scoped or globally-scoped. var declarations are hoisted, meaning declaring a variable anywhere in the code is equivalent to declaring it at the top of the function or the script.

What changed

Declares 'currentTabIndex' at the top level (outside the try block) so that it is declared in the same scope where it is referenced. This addresses the code smell where 'var currentTabIndex' was declared inside a block (the try block) but referenced outside of that binding context. By hoisting the declaration to the outer scope, the variable is properly scoped to where it is actually used.

--- a/content/assets/js/tabs.js
+++ b/content/assets/js/tabs.js
@@ -0,0 +1,1 @@
+var currentTabIndex;
javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: content/assets/js/window-hash.js:2

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 both occurrences of window with globalThis in the file content/assets/js/window-hash.js. On line 2, window.location.hash is changed to globalThis.location.hash in the if-condition, fixing the static analysis warning about preferring globalThis over window at that location. On line 3, window.location.hash is similarly changed to globalThis.location.hash inside the jQuery selector string, fixing the second warning about preferring globalThis over window. Using globalThis is the standardized ES2020 way to access the global object, making the code more portable across different JavaScript environments (browser, Node.js, Web Workers) instead of relying on the browser-specific window reference.

--- a/content/assets/js/window-hash.js
+++ b/content/assets/js/window-hash.js
@@ -2,2 +2,2 @@ $(document).ready(function(){
-  if(window.location.hash != "") {
-      $('a[href="' + window.location.hash + '"]').click()
+  if(globalThis.location.hash != "") {
+      $('a[href="' + globalThis.location.hash + '"]').click()
javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: content/assets/js/window-hash.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

This hunk replaces both occurrences of window with globalThis in the file content/assets/js/window-hash.js. On line 2, window.location.hash is changed to globalThis.location.hash in the if-condition, fixing the static analysis warning about preferring globalThis over window at that location. On line 3, window.location.hash is similarly changed to globalThis.location.hash inside the jQuery selector string, fixing the second warning about preferring globalThis over window. Using globalThis is the standardized ES2020 way to access the global object, making the code more portable across different JavaScript environments (browser, Node.js, Web Workers) instead of relying on the browser-specific window reference.

--- a/content/assets/js/window-hash.js
+++ b/content/assets/js/window-hash.js
@@ -2,2 +2,2 @@ $(document).ready(function(){
-  if(window.location.hash != "") {
-      $('a[href="' + window.location.hash + '"]').click()
+  if(globalThis.location.hash != "") {
+      $('a[href="' + globalThis.location.hash + '"]').click()
javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: content/assets/js/topofpage.js:2

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 binding. The static analysis rule flags the use of window as a non-portable way to access the global object, recommending globalThis instead as the standardized ES2020 approach that works consistently across all JavaScript environments (browsers, Node.js, Web Workers). By changing $(window).scroll(...) to $(globalThis).scroll(...), the code follows the preferred practice of using globalThis over environment-specific globals.

--- a/content/assets/js/topofpage.js
+++ b/content/assets/js/topofpage.js
@@ -2,1 +2,1 @@ $(document).ready(function(){
-     $(window).scroll(function () {
+     $(globalThis).scroll(function () {

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZZjJOKu2HDYqP_XXG6z for javascript:S125 rule
- AZmd8Pz-uPWA3VN6PKOA for javascript:S7764 rule
- AZZjJONQ2HDYqP_XXG7V for javascript:S2392 rule
- AZmd8Pw-uPWA3VN6PKN8 for javascript:S7764 rule
- AZmd8Pw-uPWA3VN6PKN9 for javascript:S7764 rule

Generated by SonarQube Agent (task: 91e65db9-17ed-4340-af75-50a0342a48df)
@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

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