fix: resolve 10 SonarQube issues in estimator.js#570
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve 10 SonarQube issues in estimator.js#570sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ45Ctw2RXnEWm2Rf4VU for javascript:S6582 rule - AZ45Ctw2RXnEWm2Rf4Vc for javascript:S7764 rule - AZ45Ctw2RXnEWm2Rf4Vd for javascript:S6594 rule - AZ45Ctw2RXnEWm2Rf4Ve for javascript:S7773 rule - AZ45Ctw2RXnEWm2Rf4Vf for javascript:S7773 rule - AZ45Ctw2RXnEWm2Rf4Vg for javascript:S7773 rule - AZ45Ctw2RXnEWm2Rf4Vh for javascript:S7764 rule - AZ45Ctw2RXnEWm2Rf4VV for javascript:S3504 rule - AZ45Ctw2RXnEWm2Rf4VW for javascript:S3504 rule - AZ45Ctw2RXnEWm2Rf4VT for javascript:S7764 rule Generated by SonarQube Agent (task: 3f5fa45a-0a29-4fe9-bbed-fc0365f90e11)
SonarQube reviewer guide
|
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 estimator.js to follow modern JavaScript best practices by replacing var declarations with const, using optional chaining, preferring globalThis over window, and replacing global functions with their Number and RegExp namespace equivalents. These changes improve code quality, readability, and maintainability while reducing potential scope-related bugs.
View Project in SonarCloud
Fixed Issues
javascript:S6582 - Prefer using an optional chain expression instead, as it's more concise and easier to read. • MAJOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:44Why is this an issue?
Optional chaining allows to safely access nested properties or methods of an object without having to check for the existence of each intermediate property manually. It provides a concise and safe way to access nested properties or methods without having to write complex and error-prone
null/undefinedchecks.What changed
Replaces the verbose logical AND check
!parent || !parent.nextElementSiblingwith the optional chaining expression!parent?.nextElementSibling. This is more concise and easier to read, as the?.operator safely handles the case whereparentis null/undefined without needing a separate check.javascript:S3504 - Unexpected var, use let or const instead. • CRITICAL • View issue
Location:
sklearn/utils/_repr_html/estimator.js:64Why is this an issue?
Variables declared with
varare function-scoped, meaning they are accessible within the entire function in which they are defined. If a variable is declared usingvaroutside of any function, it becomes a global variable and is accessible throughout the entire JavaScript program.What changed
Replaces
vardeclarations withconstfor bothdetailsElemandwasOpenvariables. Usingconstprovides proper block scoping and signals that these variables are not reassigned, following modern ES6+ best practices and eliminating the issues with function-scopedvardeclarations.javascript:S3504 - Unexpected var, use let or const instead. • CRITICAL • View issue
Location:
sklearn/utils/_repr_html/estimator.js:65Why is this an issue?
Variables declared with
varare function-scoped, meaning they are accessible within the entire function in which they are defined. If a variable is declared usingvaroutside of any function, it becomes a global variable and is accessible throughout the entire JavaScript program.What changed
Replaces
vardeclarations withconstfor bothdetailsElemandwasOpenvariables. Usingconstprovides proper block scoping and signals that these variables are not reassigned, following modern ES6+ best practices and eliminating the issues with function-scopedvardeclarations.javascript:S7764 - Prefer `globalThis` over `window`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:133Why 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
Makes two changes: (1) Replaces
window.getComputedStyle(...)withglobalThis.getComputedStyle(...)to use the standardized global object accessor instead of the browser-specificwindow. (2) Rewritescolor.match(/regex/)as/regex/.exec(color), usingRegExp.exec()instead ofString.match()for better performance when the regex doesn't use the global flag.javascript:S7773 - Prefer `Number.parseFloat` over `parseFloat`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:137Why 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 three occurrences of the global
parseFloat()function withNumber.parseFloat(). This uses the modern ES2015+Numbernamespace method instead of the global function, improving code organization, reducing global namespace pollution, and aligning with modern JavaScript standards.javascript:S7773 - Prefer `Number.parseFloat` over `parseFloat`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:138Why 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 three occurrences of the global
parseFloat()function withNumber.parseFloat(). This uses the modern ES2015+Numbernamespace method instead of the global function, improving code organization, reducing global namespace pollution, and aligning with modern JavaScript standards.javascript:S7773 - Prefer `Number.parseFloat` over `parseFloat`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:139Why 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 three occurrences of the global
parseFloat()function withNumber.parseFloat(). This uses the modern ES2015+Numbernamespace method instead of the global function, improving code organization, reducing global namespace pollution, and aligning with modern JavaScript standards.javascript:S6594 - Use the "RegExp.exec()" method instead. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:134Why is this an issue?
String.match()behaves the same way asRegExp.exec()when the regular expression does not include the global flagg. While they work the same,RegExp.exec()can be slightly faster thanString.match(). Therefore, it should be preferred for better performance.What changed
Makes two changes: (1) Replaces
window.getComputedStyle(...)withglobalThis.getComputedStyle(...)to use the standardized global object accessor instead of the browser-specificwindow. (2) Rewritescolor.match(/regex/)as/regex/.exec(color), usingRegExp.exec()instead ofString.match()for better performance when the regex doesn't use the global flag.javascript:S7764 - Prefer `globalThis` over `window`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:157Why 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
window.matchMedia(...)withglobalThis.matchMedia(...)to use the standardized ES2020 global object accessor. This makes the code more portable across JavaScript environments and follows the recommendation to preferglobalThisover environment-specific globals likewindow.javascript:S7764 - Prefer `globalThis` over `window`. • MINOR • View issue
Location:
sklearn/utils/_repr_html/estimator.js:12Why 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
window.getComputedStyle(element)withglobalThis.getComputedStyle(element)at line 12, fixing the static analysis warning about preferringglobalThisoverwindowfor accessing the global object. This makes the code more portable across JavaScript environments.SonarQube Remediation Agent uses AI. Check for mistakes.