feat(config): Add support for .jsonc extension with priority order#620
feat(config): Add support for .jsonc extension with priority order#620
Conversation
- 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>
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.jsoncfiles, 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
loadFileConfigfunction 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
.jsoncfiles are loaded correctly and that the specified priority order is strictly followed.
Changelog
Click here to see the changelog
- src/config/configLoad.ts
- Changed
defaultConfigPathtodefaultConfigPathsarray including.json5,.jsonc, and.json(line 18). - Updated
getGlobalConfigPathtogetGlobalConfigPathsto return an array of potential global config paths based on the new extensions (lines 20-23). - Refactored
loadFileConfigto first check if a specificargConfigPathis provided and load it directly (lines 26-40). - Modified
loadFileConfigto iterate throughdefaultConfigPathsto find a local config file based on the new priority order (lines 42-56). - Modified
loadFileConfigto iterate throughglobalConfigPathsto 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).
- Changed
- tests/config/configLoad.test.ts
- Updated the test for loading global config to mock
fs.statcalls for all local paths (.json5,.jsonc,.json) failing before the global.json5is found (lines 62-65). - Updated the expectation in the global config test to check that
fs.readFilewas called with the.json5global 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
.jsoncconfig file is loaded correctly when.json5is not present (lines 147-160). - Added a new test case to verify that
.json5is prioritized over.jsoncand.json(lines 162-176).
- Updated the test for loading global config to mock
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
-
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 review |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 insrc/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.
There was a problem hiding this comment.
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.
📝 WalkthroughWalkthroughThe configuration loading logic was updated to support multiple config file extensions— Assessment against linked issues
Possibly related PRs
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
defaultConfigPathsarray 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.
|
@claude please fix the CI errors. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
@claude please fix the CI errors and address the review comments. |
|
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
Deploying repomix with
|
| 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 |
…ction - Extract repeated fs.stat() logic into checkFileExists helper - Improve maintainability and reduce code duplication - Address code review feedback from @gemini-code-assist
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, andfindConfigFileto streamline file resolution. - Update
loadFileConfigto search local then global configs in the new priority order and improve error handling. - Extend tests in
configLoad.test.tsto cover.jsoncloading,.json5priority, 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}`);
Add support for .jsonc config files alongside existing .json5 and .json files.
Changes
Fixes #618
Generated with Claude Code