Skip to content

fix: handle digits after separator in defaultCamelize#301

Merged
jerryliang64 merged 2 commits intoeggjs:5.xfrom
jerryliang64:fix/camelize-digit-after-separator
Mar 5, 2026
Merged

fix: handle digits after separator in defaultCamelize#301
jerryliang64 merged 2 commits intoeggjs:5.xfrom
jerryliang64:fix/camelize-digit-after-separator

Conversation

@jerryliang64
Copy link
Contributor

@jerryliang64 jerryliang64 commented Mar 5, 2026

Summary

  • defaultCamelize regex [_-][a-z] only handled separators followed by letters, leaving separators before digits untouched (e.g. foo_00.jsfoo_00 instead of foo00)
  • Extended regex to [_-][a-z0-9] so underscores/hyphens before digits are also removed during camelization
  • Added test fixture foo_00.js and assertions covering this edge case across all caseStyle modes

Test plan

  • Existing file_loader.test.js caseStyle tests pass with new fixture
  • New test case should handle separator before digits correctly verifies Foo00 is set and Foo_00 is not
  • Full test suite passes (the 1 flaky timeout in load_service.test.js is a pre-existing parallel race condition)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved camelization so identifiers with separators (underscores/dashes) followed by digits are transformed correctly (e.g., separator+digits become contiguous capitalized segments).
  • Tests

    • Added tests verifying correct handling of separator-before-digit cases across multiple naming styles.

The regex in defaultCamelize only matched `[_-][a-z]`, so separators
followed by digits (e.g. `foo_00.js`) were left untouched, producing
`foo_00` instead of the expected `foo00`. Extend the regex to
`[_-][a-z0-9]` so that underscores and hyphens before digits are also
removed during camelization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

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 addresses a bug in the defaultCamelize utility where filenames containing separators followed by digits were not correctly camelized. The fix involves updating the regular expression used for camelization to include digits, ensuring that patterns like foo_00.js are properly transformed to foo00. New test cases have been added to validate this corrected behavior.

Highlights

  • Regex update for defaultCamelize: The defaultCamelize function's regular expression was extended from [_-][a-z] to [_-][a-z0-9] to correctly handle separators followed by digits (e.g., foo_00.js should now become foo00).
  • New test fixture and assertions: A new test fixture foo_00.js was added, along with corresponding assertions in file_loader.test.js to cover this specific edge case across various caseStyle modes and to explicitly verify Foo00 is generated, not Foo_00.
Changelog
  • lib/loader/file_loader.js
    • Updated the regular expression in defaultCamelize to include digits [0-9] when replacing separators, ensuring _00 becomes 00 instead of _00.
    • Added a comment explaining the new behavior for aaa_00.js.
  • test/fixtures/load_dirs/camelize/foo_00.js
    • Added a new empty JavaScript file to serve as a test fixture for camelization with digits.
  • test/loader/file_loader.test.js
    • Added assert(target.Foo00) to existing caseStyle tests (camel, upper, lower, firstUpper, function) to verify the new camelization behavior.
    • Introduced a new dedicated test case, should handle separator before digits correctly, to specifically assert that foo_00.js camelizes to Foo00 and not Foo_00 when caseStyle is upper.
Activity
  • Existing file_loader.test.js caseStyle tests were verified to pass with the new fixture.
  • A new test case, should handle separator before digits correctly, was added to specifically verify the correct camelization of filenames with digits after separators.
  • The full test suite was run and passed, with a known pre-existing flaky timeout in load_service.test.js noted.
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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f7bbda0-c78b-482a-a4d8-156c216b06b7

📥 Commits

Reviewing files that changed from the base of the PR and between 5591afa and 50ca87b.

📒 Files selected for processing (1)
  • test/loader/file_loader.test.js

📝 Walkthrough

Walkthrough

This change refines filename camelization to include digits after separators when capitalizing (e.g., foo_00.js -> Foo00). It updates the regex in the file loader and adds a test fixture plus tests verifying the new behavior.

Changes

Cohort / File(s) Summary
Camelization Logic
lib/loader/file_loader.js
Changed regex in defaultCamelize from /[_-][a-z]/ig to /[_-][a-z0-9]/ig so characters or digits following _/- are considered for capitalization.
Tests & Fixtures
test/fixtures/load_dirs/camelize/foo_00.js, test/loader/file_loader.test.js
Added fixture foo_00.js exporting {} and extended tests to assert foo_00 camelizes to Foo00 across case styles and lowercase-first variations; added a dedicated test for separator-before-digits handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through underscores and dashes bright,

Spotted digits hiding just out of sight,
I nudged the regex, gave numbers their cue,
Now foo_00 springs forth as proud Foo00! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: handle digits after separator in defaultCamelize' accurately and concisely describes the main change—extending the camelization regex to handle digits after separators.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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 addresses an issue in defaultCamelize where separators followed by digits were not handled correctly. The fix extends the regular expression to include digits, ensuring proper camelization for filenames like foo_00.js. The change is accompanied by comprehensive tests, including a new test fixture and assertions for various caseStyle options, which validate the fix effectively. The implementation is correct and the added tests are thorough.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/loader/file_loader.test.js`:
- Line 361: Remove the redundant bracket-notation assertion on the target
object: delete the line containing assert(!target['Foo_00']) so only the
existing assert(!target.Foo_00) remains; this removes the duplicate check and
resolves the ESLint dot-notation violation in file_loader.test.js.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 044b858b-de70-43d1-91c9-016cf194e376

📥 Commits

Reviewing files that changed from the base of the PR and between e8bb315 and 5591afa.

📒 Files selected for processing (3)
  • lib/loader/file_loader.js
  • test/fixtures/load_dirs/camelize/foo_00.js
  • test/loader/file_loader.test.js

…tation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jerryliang64 jerryliang64 merged commit e7af37b into eggjs:5.x Mar 5, 2026
33 of 35 checks passed
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