fix: resolve 5 SonarQube code quality issues#47
Open
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Open
fix: resolve 5 SonarQube code quality issues#47sonarqube-agent[bot] wants to merge 1 commit intomainfrom
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Conversation
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)
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 minor SonarQube code quality issues across the Design System codebase. Changes include replacing
windowwithglobalThisfor cross-environment compatibility, using directundefinedcomparison instead oftypeof, and switching fromString#replace()toString#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`. • MINOR • View issue
Location:
src/script/blocs/bloc-m-key-figure.js:19Why 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
Replaces
windowwithglobalThisin the IIFE invocation on line 19 of bloc-m-key-figure.js. The static analysis rule flags the use ofwindowto access the global object, recommendingglobalThisinstead for cross-environment compatibility. This change directly resolves that code smell by using the standardized ES2020globalThisreference.javascript:S7741 - Compare with `undefined` directly instead of using `typeof`. • MINOR • View issue
Location:
src/script/blocs/bloc-o-carte-interactive.js:114Why is this an issue?
Using
typeofto check forundefinedvalues is unnecessarily verbose and makes code harder to read. The patterntypeof value === 'undefined'was historically necessary in older JavaScript versions (pre-ES5) because the globalundefinedcould 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 comparisondrupalSettings.asip.map !== undefined. This addresses the code smell wheretypeofwas unnecessarily used to check for undefined values, making the code more concise and readable in line with modern JavaScript practices.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
src/script/app/_links.js:17Why 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 thearia-labelattribute value has whitespace normalized. The static analysis rule flagsString#replace()with a global regex and recommends usingString#replaceAll()instead. By switching toreplaceAll()with the same global regex, the code satisfies the rule's preference for the more explicit replacement method.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
src/script/app/_links.js:23Why 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 thetitleattribute value has whitespace normalized. The static analysis warning flagged the use ofString#replace()with a global regex at this location, recommendingString#replaceAll()instead. Switching toreplaceAll()addresses this code smell by using the preferred, more explicit replacement method.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
src/script/app/_links.js:30Why 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 appendingtargetBlankText. The static analysis warning flagged the use ofString#replace()with a global regex at this location, recommendingString#replaceAll()instead. Switching toreplaceAll()addresses this code smell by using the preferred, more explicit replacement method.SonarQube Remediation Agent uses AI. Check for mistakes.