Skip to content

Conversation

@dagalloso
Copy link

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"

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 format method failed to correctly process 8-digit RUTs, which are common for individuals over 60, resulting in malformed output. The core change involves updating the formatting logic to use precise string slicing, ensuring all valid RUT lengths are handled correctly. This enhancement improves the reliability and accuracy of the RUT formatting functionality.

Highlights

  • Bug Fix: Resolved an issue where the format method for Chilean RUTs incorrectly handled 8-digit numbers, leading to an 'undefined' segment in the formatted output.
  • Improved Formatting Logic: The format method in src/cl/rut.ts has been refactored to use string slicing, providing a more robust and accurate way to format RUTs of varying lengths.
  • Test Coverage: A new test case has been added to src/cl/rut.spec.ts specifically to validate the correct formatting of 8-digit RUTs, ensuring the fix works as expected.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 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)}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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).

Suggested change
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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant