Skip to content

feat(config): Add support for .jsonc extension with priority order#620

Merged
yamadashy merged 4 commits intomainfrom
claude/issue-618-20250531_114912
May 31, 2025
Merged

feat(config): Add support for .jsonc extension with priority order#620
yamadashy merged 4 commits intomainfrom
claude/issue-618-20250531_114912

Conversation

@yamadashy
Copy link
Owner

Add support for .jsonc config files alongside existing .json5 and .json files.

Changes

  • Implement priority order: repomix.config.json5 → repomix.config.jsonc → repomix.config.json
  • Update config file discovery for both local and global configurations
  • Add comprehensive tests for JSONC support and priority ordering
  • JSON5 parser already supports JSONC format (JSON with comments)

Fixes #618

Generated with Claude Code

- Add support for .jsonc config files alongside existing .json5 and .json
- Implement priority order: repomix.config.json5 → repomix.config.jsonc → repomix.config.json
- Update config file discovery for both local and global configurations
- Add comprehensive tests for JSONC support and priority ordering
- JSON5 parser already supports JSONC format (JSON with comments)

Fixes #618

Co-authored-by: yamadashy <yamadashy@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 31, 2025 11:55
Copy link
Contributor

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 JSONC configuration files by introducing a prioritized config discovery mechanism that checks for repomix.config.json5 first, then repomix.config.jsonc, and finally repomix.config.json, both locally and globally. It also updates the tests to validate the new behavior and ensures comprehensive logging and error handling.

Reviewed Changes

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

File Description
tests/config/configLoad.test.ts Updated tests to reflect the new priority order for loading config files, including JSONC support and verifying logger outputs.
src/config/configLoad.ts Refactored config discovery using a list of config paths with explicit priority order and updated error messaging.

Copy link
Contributor

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

Hello @yamadashy, 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!

Summary of Changes

Hello team, gemini-code-assist here with a summary of this pull request. This PR introduces support for loading configuration files with the .jsonc extension. It also establishes a clear priority order for discovering config files: repomix.config.json5 is checked first, followed by repomix.config.jsonc, and finally repomix.config.json. This priority applies to both local project configurations and global configurations. The changes involve updating the config loading logic to iterate through these extensions and adding corresponding tests to ensure the new functionality and priority order work as expected.

Highlights

  • Add .jsonc Support: Adds support for repomix.config.jsonc files, allowing users to use JSON with comments for their configuration.
  • Implement Priority Order: Defines and implements a specific search order for config files: .json5 > .jsonc > .json. The first file found in this order is used.
  • Update Config Loading Logic: Refactors the loadFileConfig function to handle the new priority order when searching for local and global configuration files.
  • Add Comprehensive Tests: Includes new and updated tests to verify that .jsonc files are loaded correctly and that the specified priority order is strictly followed.

Changelog

Click here to see the changelog
  • src/config/configLoad.ts
    • Changed defaultConfigPath to defaultConfigPaths array including .json5, .jsonc, and .json (line 18).
    • Updated getGlobalConfigPath to getGlobalConfigPaths to return an array of potential global config paths based on the new extensions (lines 20-23).
    • Refactored loadFileConfig to first check if a specific argConfigPath is provided and load it directly (lines 26-40).
    • Modified loadFileConfig to iterate through defaultConfigPaths to find a local config file based on the new priority order (lines 42-56).
    • Modified loadFileConfig to iterate through globalConfigPaths to find a global config file if no local file is found, respecting the priority order (lines 58-72).
    • Updated the log message when no config file is found to list all checked default and global paths (lines 74-78).
  • tests/config/configLoad.test.ts
    • Updated the test for loading global config to mock fs.stat calls for all local paths (.json5, .jsonc, .json) failing before the global .json5 is found (lines 62-65).
    • Updated the expectation in the global config test to check that fs.readFile was called with the .json5 global path (line 70).
    • Updated the test for no config file found to check that the log message includes all three extensions (.json5, .jsonc, .json) (lines 82-84).
    • Added a new test case to verify that a .jsonc config file is loaded correctly when .json5 is not present (lines 147-160).
    • Added a new test case to verify that .json5 is prioritized over .jsonc and .json (lines 162-176).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


Config files, extensions new,
JSONC joins the view.
Priority set,
No need to fret,
Your settings will see through.

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.

@yamadashy
Copy link
Owner Author

@coderabbitai review

@codecov
Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.30%. Comparing base (6f5bb2e) to head (80e1bef).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #620      +/-   ##
==========================================
+ Coverage   90.24%   90.30%   +0.06%     
==========================================
  Files          96       96              
  Lines        4920     4932      +12     
  Branches     1020     1027       +7     
==========================================
+ Hits         4440     4454      +14     
+ Misses        480      478       -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.

Copy link
Contributor

@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 effectively adds support for .jsonc configuration files and implements a clear priority order (.json5 -> .jsonc -> .json) for discovering both local and global configuration files. The changes are well-targeted, and the updated logic in loadFileConfig is clear and directly addresses the requirements.

The accompanying tests are comprehensive and cover the new functionality well, including the priority order and fallback mechanisms. This significantly increases confidence in the correctness of the changes. Great job on the thorough testing, especially the test ensuring that file stats are not called unnecessarily once a higher-priority file is found!

I have one suggestion regarding code maintainability that would further improve the loadFileConfig function.

Summary of Findings

  • Code Duplication: The file existence check logic (fs.stat().then().catch()) is duplicated in src/config/configLoad.ts. Refactoring this into a helper function would improve code clarity and maintainability.

Merge Readiness

The pull request is in good shape and implements the desired functionality effectively with strong test coverage. There is one suggestion for a minor refactor to improve maintainability by reducing code duplication. Addressing this point would make the code even cleaner. As I am an AI, I am not authorized to approve pull requests. Please ensure further review and approval from the maintainers before merging, especially after considering the suggested change.

Copy link
Contributor

@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 effectively adds support for .jsonc configuration files and establishes a clear priority order (.json5.jsonc.json) for loading configurations, enhancing flexibility for users. The changes are well-implemented, and the accompanying tests are comprehensive, particularly in verifying the priority logic and short-circuiting behavior.

I have one suggestion for improving code maintainability in src/config/configLoad.ts. Overall, great work on this feature!

Summary of Findings

  • Code Duplication in File Existence Check: In src/config/configLoad.ts, the logic to check if a file exists and is a file (fs.stat().then().catch()) is duplicated in three places. Extracting this into a helper function would improve code readability and maintainability.

Merge Readiness

This pull request introduces a valuable feature and is generally well-implemented with thorough tests. There is one medium-severity suggestion regarding code duplication that I recommend addressing to enhance maintainability. Once that is considered, the PR should be in excellent shape for merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval from the team.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 31, 2025

📝 Walkthrough

Walkthrough

The configuration loading logic was updated to support multiple config file extensions—.json5, .jsonc, and .json—when searching for configuration files. The code now checks for these files in a prioritized order both locally and globally, loading the first one found. If a specific config path is provided, only that file is checked. If no config file is found, an empty config object is returned and a message is logged listing all checked paths. The test suite was expanded to verify the new priority and fallback behavior.

Assessment against linked issues

Objective Addressed Explanation
Support .jsonc extension for the config (#618)
Prioritize .json5 > .jsonc > .json when loading config files (#618)
Ensure fallback to global config and empty object if no config found (#618)

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f5bb2e and 99e093d.

📒 Files selected for processing (2)
  • src/config/configLoad.ts (1 hunks)
  • tests/config/configLoad.test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/config/configLoad.ts (2)
src/shared/logger.ts (1)
  • logger (88-88)
src/shared/errorHandle.ts (1)
  • RepomixError (5-10)
🪛 GitHub Check: codecov/patch
src/config/configLoad.ts

[warning] 39-39: src/config/configLoad.ts#L39
Added line #L39 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Test (windows-latest, 24.x)
  • GitHub Check: Test (windows-latest, 21.x)
  • GitHub Check: Test (windows-latest, 22.x)
  • GitHub Check: Test (windows-latest, 18.x)
  • GitHub Check: Test (windows-latest, 23.x)
  • GitHub Check: Build and run (windows-latest, 19.x)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (9)
src/config/configLoad.ts (5)

18-18: LGTM! Clear priority order definition.

The defaultConfigPaths array correctly implements the required priority order (.json5 > .jsonc > .json) as specified in the PR objectives.


20-23: Good refactor to support multiple global config paths.

The function correctly maps the default config paths to global directory paths, maintaining consistency with the priority order.


42-56: Excellent implementation of priority-based config discovery.

The loop correctly implements the priority order, checking each config file in sequence and loading the first one found. The trace logging provides good visibility into the discovery process.


58-72: Consistent implementation for global config discovery.

The global config discovery follows the same priority-based pattern as local discovery, ensuring consistent behavior across both local and global configuration loading.


74-79: Improved user experience with comprehensive logging.

The updated log message clearly shows all checked paths for both local and global configs, helping users understand where they can place configuration files and the priority order.

tests/config/configLoad.test.ts (4)

62-65: Properly updated test for priority-based config discovery.

The test correctly mocks the new behavior where all three local config files are checked in priority order before falling back to the global .json5 config file.

Also applies to: 70-70


82-84: Good test coverage for updated logging behavior.

The test properly verifies that all three config file extensions are mentioned in the log message when no config is found, ensuring users understand all the options available.


147-160: Essential test for .jsonc fallback behavior.

This test correctly verifies that when .json5 is not available, the system falls back to .jsonc as the next priority, which is a key part of the new priority order functionality.


162-176: Critical test for priority order early termination.

This test validates the important behavior that when the highest priority config file (.json5) is found, the system immediately uses it without checking lower priority files. The assertion expect(fs.stat).toHaveBeenCalledTimes(1) confirms this optimization.

@yamadashy
Copy link
Owner Author

@claude please fix the CI errors.

@claude
Copy link
Contributor

claude bot commented May 31, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@yamadashy
Copy link
Owner Author

@claude please fix the CI errors and address the review comments.

@claude
Copy link
Contributor

claude bot commented May 31, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

…t for RepomixError when argConfigPath is provided but file doesn't exist - Improve test coverage for error handling in configLoad.ts - Address code review feedback from @coderabbitai
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 31, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: 80e1bef
Status: ✅  Deploy successful!
Preview URL: https://0ed18551.repomix.pages.dev
Branch Preview URL: https://claude-issue-618-20250531-11.repomix.pages.dev

View logs

…ction - Extract repeated fs.stat() logic into checkFileExists helper - Improve maintainability and reduce code duplication - Address code review feedback from @gemini-code-assist
@yamadashy yamadashy requested a review from Copilot May 31, 2025 12:17
Copy link
Contributor

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 .jsonc configuration files alongside existing .json5 and .json files, and implements a priority order for config file resolution.

  • Updates config file discovery to check for repomix.config.json5, repomix.config.jsonc, then repomix.config.json
  • Enhances tests to verify local and global config file lookup and error handling

Reviewed Changes

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

File Description
tests/config/configLoad.test.ts Adjusted tests to reflect new config file priority and logging messages
src/config/configLoad.ts Updated logic to iterate over multiple default config file candidates

…ction - Extract findConfigFile helper to eliminate duplication between local and global config lookup - Improve code readability and maintainability - Address code review feedback from @Copilot
@yamadashy yamadashy requested a review from Copilot May 31, 2025 12:23
Copy link
Contributor

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

Adds support for .jsonc config files and refactors configuration discovery to use a priority order across .json5, .jsonc, and .json.

  • Introduce defaultConfigPaths, checkFileExists, and findConfigFile to streamline file resolution.
  • Update loadFileConfig to search local then global configs in the new priority order and improve error handling.
  • Extend tests in configLoad.test.ts to cover .jsonc loading, .json5 priority, and error cases.

Reviewed Changes

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

File Description
tests/config/configLoad.test.ts Updated imports, expectations for .json5, added tests for .jsonc support, priority ordering, and missing config errors.
src/config/configLoad.ts Replaced single default path with prioritized list, added helpers for existence checks, and refactored logging and error flows.
Comments suppressed due to low confidence (2)

tests/config/configLoad.test.ts:147

  • No test covers the fallback to repomix.config.json when both repomix.config.json5 and repomix.config.jsonc are missing. Consider adding a test for that scenario.
test('should load .jsonc config file with priority order', async () => {

src/config/configLoad.ts:59

  • [nitpick] The error message for a missing specific config only references the provided path. Including the resolved absolute path could improve clarity during debugging.
throw new RepomixError(`Config file not found at ${argConfigPath}`);

@yamadashy yamadashy merged commit 66f714d into main May 31, 2025
61 checks passed
@yamadashy yamadashy deleted the claude/issue-618-20250531_114912 branch May 31, 2025 12:27
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.

Support JSONC extension for the config

2 participants