Skip to content

feat(br): support new cnpj format#153

Open
taj wants to merge 1 commit intokoblas:mainfrom
taj:support-new-br-cnpj-format
Open

feat(br): support new cnpj format#153
taj wants to merge 1 commit intokoblas:mainfrom
taj:support-new-br-cnpj-format

Conversation

@taj
Copy link
Copy Markdown

@taj taj commented Apr 8, 2026

Hi!

Brazil's CNPJ format is expanding to allow letters A-Z in the first 12 positions , while the last 2 check digits remain numeric.

Backward-compatible — existing numeric CNPJs validate identically.

Reference: https://kpmg.com/us/en/taxnewsflash/news/2026/03/tnf-brazi-new-alphanumeric-format-for-taxpayer-registry.html


This is my first contribution to this project, so happy to adjust the approach if it doesn't align with how you'd prefer to handle this. Let me know if any changes are needed!

And thank you!

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 introduces crucial updates to the Brazilian CNPJ validation and formatting utilities. It enables the system to correctly process the upcoming alphanumeric CNPJ format, which will be adopted starting July 2026, while ensuring that all existing numeric CNPJs continue to be handled without issue. The changes primarily involve adapting the character interpretation and validation logic to accommodate letters in the identifier's main body.

Highlights

  • Alphanumeric CNPJ Support: Implemented support for the new alphanumeric Brazilian CNPJ format, which allows letters A-Z in the first 12 positions while retaining numeric check digits.
  • Backward Compatibility: Ensured that existing numeric CNPJs remain valid and are processed identically, maintaining backward compatibility.
  • Checksum Calculation Update: Modified the checksum calculation logic to correctly interpret alphanumeric characters based on their ASCII values for the first 12 positions.
  • Enhanced Validation: Updated validation rules to accept alphanumeric characters in the main body of the CNPJ and specifically enforce numeric characters for the two check digits.
  • Comprehensive Test Cases: Added new test cases to cover formatting and validation of alphanumeric CNPJs, including scenarios with lowercase input, incorrect checksums, and invalid check digits.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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
Copy Markdown

@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 updates the CNPJ validation logic to support the new alphanumeric format starting in July 2026, while maintaining compatibility with legacy numeric-only CNPJs. The implementation correctly updates the checksum calculation and validation rules. I have provided a high-severity feedback comment suggesting that the clean function should normalize inputs to uppercase to ensure consistent checksum calculation and formatting for alphanumeric CNPJs.

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