Skip to content

fix: resolve 5 SonarQube code quality issues#47

Open
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
remediate-main-20260509-090146-48544074
Open

fix: resolve 5 SonarQube code quality issues#47
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
remediate-main-20260509-090146-48544074

Conversation

@sonarqube-agent
Copy link
Copy Markdown

This PR fixes 5 minor SonarQube code quality issues across the Design System codebase. Changes include replacing window with globalThis for cross-environment compatibility, using direct undefined comparison instead of typeof, and switching from String#replace() to String#replaceAll() for global regex replacements. These improvements align the code with modern JavaScript best practices and reduce technical debt.

View Project in SonarCloud


Fixed Issues

javascript:S7764 - Prefer `globalThis` over `window`. • MINORView issue

Location: src/script/blocs/bloc-m-key-figure.js:19

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

Replaces window with globalThis in the IIFE invocation on line 19 of bloc-m-key-figure.js. The static analysis rule flags the use of window to access the global object, recommending globalThis instead for cross-environment compatibility. This change directly resolves that code smell by using the standardized ES2020 globalThis reference.

--- a/src/script/blocs/bloc-m-key-figure.js
+++ b/src/script/blocs/bloc-m-key-figure.js
@@ -19,1 +19,1 @@ $(function ($, win) {
-}(jQuery, window));
+}(jQuery, globalThis));
javascript:S7741 - Compare with `undefined` directly instead of using `typeof`. • MINORView issue

Location: src/script/blocs/bloc-o-carte-interactive.js:114

Why is this an issue?

Using typeof to check for undefined values is unnecessarily verbose and makes code harder to read. The pattern typeof value === 'undefined' was historically necessary in older JavaScript versions (pre-ES5) because the global undefined could be reassigned. However, this is no longer a concern in modern JavaScript environments.

What changed

Replaces the verbose typeof drupalSettings.asip.map !== 'undefined' check with a direct comparison drupalSettings.asip.map !== undefined. This addresses the code smell where typeof was unnecessarily used to check for undefined values, making the code more concise and readable in line with modern JavaScript practices.

--- a/src/script/blocs/bloc-o-carte-interactive.js
+++ b/src/script/blocs/bloc-o-carte-interactive.js
@@ -114,1 +114,1 @@ $(document).ready(function () {
-    typeof drupalSettings.asip.map !== 'undefined' ) {
+    drupalSettings.asip.map !== undefined ) {
javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINORView issue

Location: src/script/app/_links.js:17

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 changes .replace(/\s+/g, ' ') to .replaceAll(/\s+/g, ' ') on line 17 of _links.js, where the aria-label attribute value has whitespace normalized. The static analysis rule flags String#replace() with a global regex and recommends using String#replaceAll() instead. By switching to replaceAll() with the same global regex, the code satisfies the rule's preference for the more explicit replacement method.

--- a/src/script/app/_links.js
+++ b/src/script/app/_links.js
@@ -17,1 +17,1 @@ var fn_target_blank = function() {
-            var title = $(this).attr('aria-label').replace(/\s+/g, ' ').trim();
+            var title = $(this).attr('aria-label').replaceAll(/\s+/g, ' ').trim();
javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINORView issue

Location: src/script/app/_links.js:23

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 changes .replace(/\s+/g, ' ') to .replaceAll(/\s+/g, ' ') on line 23 of _links.js, where the title attribute value has whitespace normalized. The static analysis warning flagged the use of String#replace() with a global regex at this location, recommending String#replaceAll() instead. Switching to replaceAll() addresses this code smell by using the preferred, more explicit replacement method.

--- a/src/script/app/_links.js
+++ b/src/script/app/_links.js
@@ -23,1 +23,1 @@ var fn_target_blank = function() {
-            var title = $(this).attr('title').replace(/\s+/g, ' ').trim();
+            var title = $(this).attr('title').replaceAll(/\s+/g, ' ').trim();
javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINORView issue

Location: src/script/app/_links.js:30

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 changes .replace(/\s+/g, ' ') to .replaceAll(/\s+/g, ' ') on line 30 of _links.js, where the text content has whitespace normalized before appending targetBlankText. The static analysis warning flagged the use of String#replace() with a global regex at this location, recommending String#replaceAll() instead. Switching to replaceAll() addresses this code smell by using the preferred, more explicit replacement method.

--- a/src/script/app/_links.js
+++ b/src/script/app/_links.js
@@ -30,1 +30,1 @@ var fn_target_blank = function() {
-                return $(this).text().replace(/\s+/g, ' ').trim() + targetBlankText
+                return $(this).text().replaceAll(/\s+/g, ' ').trim() + targetBlankText

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZxrBYo0c5mXC10on-t5 for javascript:S7741 rule
- AZxrBYoic5mXC10on-t0 for javascript:S7764 rule
- AZxrBYoGc5mXC10on-tw for javascript:S7781 rule
- AZxrBYoGc5mXC10on-tx for javascript:S7781 rule
- AZxrBYoGc5mXC10on-ty for javascript:S7781 rule

Generated by SonarQube Agent (task: 56e455e6-64a2-4b06-bfa4-0bee023fe504)
@sonarqube-agent
Copy link
Copy Markdown
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.

0 participants