-
-
Notifications
You must be signed in to change notification settings - Fork 410
refactor: replace unsafe Number constructor with type-safe alternatives #7777 #8584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Beutife, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the codebase to eliminate the unsafe usage of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a great step towards improving type safety by replacing the unsafe Number() constructor. The introduction of bigintToNumber for bigint conversions and the switch to parseInt for strings are excellent changes. My review focuses on ensuring the new parsing logic is as robust as possible. I've pointed out several instances where parseInt is used without a radix, which can lead to unexpected behavior. I've also noted a few minor code style issues. Overall, this is a valuable refactoring that enhances code quality.
| return { | ||
| rootHex, | ||
| epoch: Number(epoch), | ||
| epoch: parseInt(epoch), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## unstable #8584 +/- ##
=========================================
Coverage 51.90% 51.91%
=========================================
Files 848 849 +1
Lines 65797 65817 +20
Branches 4795 4797 +2
=========================================
+ Hits 34153 34166 +13
- Misses 31575 31582 +7
Partials 69 69 🚀 New features to boost your workflow:
|
Motivation
Remove usage of
Number()constructor which is unsafe because:anyas parameter, allowing invalid types without TypeScript errorsNaNwhen given invalid inputDescription
Added
bigintToNumber()utility function in@lodestar/utilsModified
Number(bigint)withbigintToNumber(bigint)Number(string)withparseInt(string, 10)Closes #issue_number
#7771
Steps to test or reproduce