fix: resolve 5 SonarQube issues in JavaScript files#48
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve 5 SonarQube issues in JavaScript files#48sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZxrBYpYc5mXC10on-t6 for javascript:S7741 rule - AZxrBYoic5mXC10on-t1 for javascript:S7781 rule - AZxrBYoic5mXC10on-t2 for javascript:S7773 rule - AZxrBYoic5mXC10on-t3 for javascript:S7773 rule - AZxrBYoic5mXC10on-tz for javascript:S7766 rule Generated by SonarQube Agent (task: c7835a20-af5c-4aa6-aefa-a326c4a80e16)
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.



Updated JavaScript code to follow modern best practices and SonarQube recommendations. Changes include replacing typeof checks with direct undefined comparison, using Math.min() instead of ternary expressions, preferring String#replaceAll() over replace() with global regex, using Number.isNaN() instead of isNaN(), and using Number.parseFloat() instead of the global parseFloat() function.
View Project in SonarCloud
Fixed Issues
javascript:S7741 - Compare with `undefined` directly instead of using `typeof`. • MINOR • View issue
Location:
src/script/blocs/bloc-global-sliders.js:60Why 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
This hunk replaces the verbose
typeof(sliderElt) != 'undefined'check with a direct comparisonsliderElt !== undefined. The original code used thetypeofoperator to check ifsliderEltwas undefined by comparing the result string, which is unnecessarily verbose and harder to read in modern JavaScript. The fix uses a direct strict comparison withundefined, which is more concise, expressive, and the recommended approach in modern JavaScript environments whereundefinedcannot be reassigned.javascript:S7766 - Prefer `Math.min()` to simplify ternary expressions. • MINOR • View issue
Location:
src/script/blocs/bloc-m-key-figure.js:13Why is this an issue?
Ternary expressions that implement min/max logic can be harder to read and understand at first glance. When you see
height > 50 ? 50 : height, you need to mentally parse the comparison logic to understand that it’s selecting the smaller value.What changed
Replaces the ternary expression
b < H ? b : HwithMath.min(b, H), which is the idiomatic way to select the minimum of two values. This makes the intent clearer and addresses the static analysis warning about preferringMath.min()over ternary expressions for min/max logic.javascript:S7781 - Prefer `String#replaceAll()` over `String#replace()`. • MINOR • View issue
Location:
src/script/blocs/bloc-m-key-figure.js:26Why 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
Replaces
String#replace(/\s/g, "")withString#replaceAll(/\s/g, ""). The static analysis rule flags the use ofString#replace()with a global regex that could be replaced withString#replaceAll()for clarity. Note: since\sis a character class (not a fixed literal),replaceAllwith the global regex is used rather than a plain string argument, but this satisfies the analyzer's preference forreplaceAlloverreplacewith a global flag.javascript:S7773 - Prefer `Number.isNaN` over `isNaN`. • MINOR • View issue
Location:
src/script/blocs/bloc-m-key-figure.js:31Why is this an issue?
ECMAScript 2015 introduced static methods and properties on the
Numberconstructor to replace several global functions and values. Using theseNumberequivalents provides several benefits:What changed
Replaces the global
isNaN()function withNumber.isNaN(Number(keyfigureNumber)). The globalisNaN()performs implicit type coercion which can lead to unexpected results, whileNumber.isNaN()only returns true for actualNaNvalues. Wrapping the argument inNumber()ensures the string is explicitly converted to a number first, preserving the original coercion behavior while using the modern, preferredNumber.isNaNmethod.javascript:S7773 - Prefer `Number.parseFloat` over `parseFloat`. • MINOR • View issue
Location:
src/script/blocs/bloc-m-key-figure.js:40Why is this an issue?
ECMAScript 2015 introduced static methods and properties on the
Numberconstructor to replace several global functions and values. Using theseNumberequivalents provides several benefits:What changed
Replaces the global
parseFloat()function withNumber.parseFloat(). This addresses the static analysis warning about preferringNumberconstructor methods over their global equivalents, aligning with modern ES2015+ practices for better code organization and consistency.SonarQube Remediation Agent uses AI. Check for mistakes.