Conversation
Summary of ChangesHello @dagalloso, 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 addresses a critical formatting bug in the Chilean RUT utility. Previously, 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.
Code Review
This pull request successfully addresses an issue with formatting 8-digit Chilean RUTs. The previous implementation failed on shorter RUTs, and the new logic using slice with negative offsets correctly handles both 8 and 9-digit RUTs. A new test case has been added to cover this scenario, which is great. I've provided one suggestion to improve the readability and maintainability of the formatting logic using a regular expression.
| const [a, b, c, d] = strings.splitAt(value, 2, 5, 8); | ||
|
|
||
| return `${a}.${b}.${c}-${d}`; | ||
| return `${value.slice(0, -7)}.${value.slice(-7, -4)}.${value.slice(-4, -1)}-${value.slice(-1)}`; |
There was a problem hiding this comment.
While the use of multiple slice() calls is correct, it can be a bit difficult to read and verify the indices at a glance. A regular expression can make this formatting logic more declarative and easier to understand. It also has the benefit of not producing a malformed string if the input doesn't match the expected RUT structure (e.g., for inputs with an incorrect length).
| return `${value.slice(0, -7)}.${value.slice(-7, -4)}.${value.slice(-4, -1)}-${value.slice(-1)}`; | |
| return value.replace(/^(\d{1,2})(\d{3})(\d{3})(.)$/, '$1.$2.$3-$4'); |
The current implementation of the format method does not support 8-digit RUTs (Chile), resulting in an unexpected undefined at the end. This type of RUT is common among people over 60 years old.
Current response:
"77.272.305-undefined"Expected:
"7.727.230-5"