Skip to content
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

feat(file): add C++ file extensions support for comment stripping #435

Merged
merged 3 commits into from
Mar 28, 2025

Conversation

AdijeShen
Copy link
Contributor

  • Add support for .h, .hpp, .cpp, .cc, and .cxx file extensions
  • Configure all C++ extensions to use the existing C comment stripper
  • Add comprehensive test cases for each supported C++ extension
  • Verify correct handling of various comment styles in each file type

This enhancement improves code processing capabilities for C++ projects.

Checklist

  • Run npm run test
  • Run npm run lint

@AdijeShen AdijeShen requested a review from yamadashy as a code owner March 26, 2025 09:58
@AdijeShen
Copy link
Contributor Author

Hi @yamadashy, thanks for maintaining this awesome repomix tool!

While using repomix to pack my C++ repository (which primarily contains .h and .cc files), I noticed it wasn't correctly stripping comments from these file extensions. This PR adds support for common C++ file extensions (.h, .hpp, .cpp, .cc, and .cxx) by configuring them to use the existing C comment stripper.

I've also added comprehensive test cases for each supported extension to verify proper handling of various comment styles in each file type. All tests pass successfully.

This enhancement should significantly improve repomix's code processing capabilities for C++ projects. Let me know if you'd like any changes to this implementation!

Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.23%. Comparing base (fac2bff) to head (a0a7f54).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/core/file/fileManipulate.ts 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #435      +/-   ##
==========================================
+ Coverage   85.19%   85.23%   +0.03%     
==========================================
  Files          87       87              
  Lines        4242     4266      +24     
  Branches      837      840       +3     
==========================================
+ Hits         3614     3636      +22     
- Misses        628      630       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Add support for .h, .hpp, .cpp, .cc, and .cxx file extensions
- Configure all C++ extensions to use the existing C comment stripper
- Add comprehensive test cases for each supported C++ extension
- Verify correct handling of various comment styles in each file type

This enhancement improves code processing capabilities for C++ projects.

Signed-off-by: adijeshen <[email protected]>
@yamadashy yamadashy requested a review from Copilot March 27, 2025 15:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for C++ file extensions to the comment stripping functionality.

  • New test cases for .h, .hpp, .cpp, .cc, and .cxx files covering various comment styles were added.
  • The core file manipulator was updated to map these C++ extensions to the existing C comment stripper.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/core/file/fileManipulate.test.ts Added test cases for C++ file extensions and comment removal cases.
src/core/file/fileManipulate.ts Configured C++ extensions to use the existing C comment stripper.

@yamadashy
Copy link
Owner

Hi, @AdijeShen!

Thank you for your PR!

I tested it with this repository and it works great, the code looks perfect!
https://github.com/nlohmann/json

I noticed that documentation comments were still remaining, so I tried to address that issue.
I don't have much experience with C++, so I'm wondering if documentation comments should be preserved instead?

@yamadashy yamadashy requested a review from Copilot March 28, 2025 04:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for comment stripping in C++ files by configuring all C++ extensions (.h, .hpp, .cpp, .cc, .cxx) to use a dedicated manipulator and by adding comprehensive test cases to validate the behavior.

  • Added a new CppManipulator class to handle C++ file types using the existing C comment stripper.
  • Extended the test suite with multiple test cases covering various comment formats, including triple slash comments.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/core/file/fileManipulate.test.ts Added new test cases for header, source, and triple slash comment removal across multiple C++ file extensions.
src/core/file/fileManipulate.ts Introduced the CppManipulator class and updated extension mappings for C++ files.
Comments suppressed due to low confidence (1)

src/core/file/fileManipulate.ts:55

  • [nitpick] Consider handling multiple occurrences of '///' on a single line—for example, by using a regular expression—to ensure all triple slash comments are removed consistently.
const tripleSlashIndex = line.indexOf('///');

@AdijeShen
Copy link
Contributor Author

Thanks for reviewing and testing the PR!

Regarding documentation comments - I believe they should not be preserved during the stripping process. The purpose of --remove-comments seems to be creating compact code archives, and documentation comments (even the triple-slash and /** */ varieties) would add unnecessary bulk to the packaged repository.

Your implementation to handle the triple-slash comments looks good to me - thanks for enhancing my initial contribution!

@yamadashy
Copy link
Owner

@AdijeShen
Thank you for confirming!

I'll merge this PR now. Thank you so much for your contribution!!

If you have any other ideas in the future, please feel free to contribute again!

@yamadashy yamadashy merged commit 21a9c0b into yamadashy:main Mar 28, 2025
52 checks passed
@yamadashy
Copy link
Owner

@AdijeShen
This feature has been released in 0.3.1!
https://github.com/yamadashy/repomix/releases/tag/v0.3.1

Thank you for your contribution! Looking forward to your future contributions!

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.

2 participants