fix: resolve 4 SonarQube code quality issues in JavaScript#46
Open
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Open
fix: resolve 4 SonarQube code quality issues in JavaScript#46sonarqube-agent[bot] wants to merge 1 commit intomainfrom
sonarqube-agent[bot] wants to merge 1 commit intomainfrom
Conversation
Fixed issues: - AZxrBYnQc5mXC10on-tv for javascript:S7764 rule - AZxrBYo0c5mXC10on-t4 for javascript:S7741 rule - AZxrBYnAc5mXC10on-tt for javascript:S7773 rule - AZxrBYnAc5mXC10on-tu for javascript:S7773 rule Generated by SonarQube Agent (task: 9717c2b3-d84d-4719-ba6d-45dee5a52dbd)
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.



Fixed code smells by replacing typeof checks with direct undefined comparisons, replacing global isNaN() with Number.isNaN() for proper NaN detection, and using globalThis instead of window for environment-agnostic global object access. These changes align with modern JavaScript best practices and improve code reliability.
View Project in SonarCloud
Fixed Issues
javascript:S7741 - Compare with `undefined` directly instead of using `typeof`. • MINOR • View issue
Location:
src/script/blocs/bloc-o-carte-interactive.js:113Why 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 two
typeof ... !== 'undefined'checks with direct comparisons toundefined. Specifically,typeof drupalSettings.asip !== 'undefined'becomesdrupalSettings.asip !== undefinedandtypeof drupalSettings.asip.map !== 'undefined'becomesdrupalSettings.asip.map !== undefined. This addresses the code smell about using unnecessarily verbosetypeofchecks for undefined values, making the code more concise and readable by using directundefinedcomparisons instead.javascript:S7773 - Prefer `Number.isNaN` over `isNaN`. • MINOR • View issue
Location:
src/script/app/_widget-access.js:35Why 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
This hunk replaces both occurrences of the global
isNaN()function withNumber.isNaN()on line 35. The static analysis flagged two uses of the globalisNaNon that line —isNaN(x)andisNaN(y)— as code smells because the globalisNaN()performs type coercion before checking, which can lead to unexpected results. By changing toNumber.isNaN(x)andNumber.isNaN(y), the code now uses the modern ES2015+ equivalent that only returnstruefor actualNaNvalues without type coercion, aligning with modern JavaScript best practices and resolving both warnings.javascript:S7773 - Prefer `Number.isNaN` over `isNaN`. • MINOR • View issue
Location:
src/script/app/_widget-access.js:35Why 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
This hunk replaces both occurrences of the global
isNaN()function withNumber.isNaN()on line 35. The static analysis flagged two uses of the globalisNaNon that line —isNaN(x)andisNaN(y)— as code smells because the globalisNaN()performs type coercion before checking, which can lead to unexpected results. By changing toNumber.isNaN(x)andNumber.isNaN(y), the code now uses the modern ES2015+ equivalent that only returnstruefor actualNaNvalues without type coercion, aligning with modern JavaScript best practices and resolving both warnings.javascript:S7764 - Prefer `globalThis` over `window`. • MINOR • View issue
Location:
src/script/app/app.js:6Why 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
This hunk replaces
windowwithglobalThisin the jQuery focus call$(window).focus()→$(globalThis).focus(). This directly fixes the code smell warning about preferringglobalThisoverwindowfor accessing the global object, asglobalThisis the standardized, environment-agnostic way to reference the global object across all JavaScript environments (browsers, Node.js, Web Workers).SonarQube Remediation Agent uses AI. Check for mistakes.