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: Add support for JSON5 in configuration files #366

Merged
merged 3 commits into from
Feb 22, 2025

Conversation

yamadashy
Copy link
Owner

Closes #346

Description

This PR adds support for JSON5 in configuration files, allowing for a more flexible and developer-friendly configuration experience.

Changes

  • Replace JSON.parse with JSON5.parse for configuration file loading
  • Update tests to cover JSON5 features (comments, trailing commas)
  • Update documentation to reflect JSON5 support
  • Add json5 package as a dependency

Testing

  • Added new test cases specifically for JSON5 features
  • Tested with configuration files containing comments and trailing commas
  • Verified backward compatibility with standard JSON

Documentation

  • Updated README.md to document JSON5 support and features
  • Added example configuration using JSON5 syntax

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

Warning

Rate limit exceeded

@yamadashy has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 10a6327 and e995a7d.

📒 Files selected for processing (3)
  • README.md (3 hunks)
  • biome.json (1 hunks)
  • repomix.config.json (1 hunks)
📝 Walkthrough

Walkthrough

The changes update the configuration file loader to support JSON5 syntax. The documentation in the README now details JSON5 features such as comments, trailing commas, unquoted property names, and relaxed string syntax. The configuration example has been adjusted to illustrate these JSON5 syntax features properly. Alongside these documentation updates, the JSON parsing in the configuration loader has been modified to use the JSON5 library instead of stripping comments from JSON, and error messages have been updated accordingly. A new dependency on the JSON5 library has been added to the dependency list in the package configuration. Finally, a test case has been introduced to ensure that the configuration loader successfully handles JSON5 syntax elements.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Loader as Config Loader
    participant FS as File System
    participant JSON5 as JSON5 Parser

    Caller->>Loader: Call loadAndValidateConfig(file)
    Loader->>FS: Read file content (fs.readFile)
    FS-->>Loader: Return file content
    Loader->>JSON5: Parse content (JSON5.parse)
    JSON5-->>Loader: Return parsed configuration
    Loader->>Caller: Return configuration object
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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

cloudflare-workers-and-pages bot commented Feb 22, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: e995a7d
Status: ✅  Deploy successful!
Preview URL: https://1499637a.repomix.pages.dev
Branch Preview URL: https://feat-config-trailing-commas.repomix.pages.dev

View logs

Copy link

codecov bot commented Feb 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.43%. Comparing base (34c53c8) to head (e995a7d).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #366   +/-   ##
=======================================
  Coverage   89.43%   89.43%           
=======================================
  Files          66       66           
  Lines        2914     2914           
  Branches      594      594           
=======================================
  Hits         2606     2606           
  Misses        308      308           

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

- Replace JSON.parse with JSON5.parse for configuration file loading
- Update tests to cover JSON5 features (comments, trailing commas)
- Update documentation to reflect JSON5 support
- Add json5 package as a dependency
@yamadashy yamadashy force-pushed the feat/config-trailing-commas branch 2 times, most recently from 10a6327 to fe82fcb Compare February 22, 2025 06:22
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: 0

🧹 Nitpick comments (2)
tests/config/configLoad.test.ts (1)

111-140: Consider expanding test coverage for JSON5 features.

While the test case covers basic JSON5 features like comments, unquoted property names, and trailing commas, consider adding tests for:

  • Hexadecimal numbers
  • Single-quoted strings
  • Error cases specific to JSON5 syntax

Apply this diff to add more test cases:

 test('should parse config file with JSON5 features', async () => {
   const configWithJSON5Features = `{
     // Output configuration
     output: {
       filePath: 'test-output.txt',
       style: 'plain',
+      hexValue: 0xFF,
+      singleQuoted: 'value',
     },
     /* Ignore configuration */
     ignore: {
       useGitignore: true, // Use .gitignore file
       customPatterns: [
         '*.log',
         '*.tmp',
         '*.temp', // Trailing comma
       ],
     },
   }`;

   vi.mocked(fs.readFile).mockResolvedValue(configWithJSON5Features);
   vi.mocked(fs.stat).mockResolvedValue({ isFile: () => true } as Stats);

   const result = await loadFileConfig(process.cwd(), 'test-config.json');
   expect(result).toEqual({
     output: { 
       filePath: 'test-output.txt',
       style: 'plain',
+      hexValue: 255,
+      singleQuoted: 'value',
     },
     ignore: {
       useGitignore: true,
       customPatterns: ['*.log', '*.tmp', '*.temp'],
     },
   });
 });

+test('should handle JSON5 syntax errors', async () => {
+  const invalidJSON5 = `{
+    output: {
+      filePath: 'test-output.txt'
+      style: 'plain' // Missing comma
+    }
+  }`;
+
+  vi.mocked(fs.readFile).mockResolvedValue(invalidJSON5);
+  vi.mocked(fs.stat).mockResolvedValue({ isFile: () => true } as Stats);
+
+  await expect(loadFileConfig(process.cwd(), 'test-config.json')).rejects.toThrow('Invalid JSON5');
+});
README.md (1)

593-598: Consider enhancing JSON5 feature documentation.

While the documentation covers the key JSON5 features, consider:

  • Adding links to JSON5 specification for each feature
  • Providing examples for each JSON5 feature

Apply this diff to enhance the documentation:

 The configuration file supports [JSON5](https://json5.org/) syntax, which allows:
-Comments (both single-line and multi-line)
-Trailing commas in objects and arrays
-Unquoted property names
-More relaxed string syntax
+- Comments (both single-line and multi-line)
+  ```json5
+  {
+    // Single-line comment
+    /* Multi-line
+       comment */
+  }
+  ```
+- Trailing commas in objects and arrays
+  ```json5
+  {
+    array: [1, 2, 3,],
+    object: {
+      key: 'value',
+    },
+  }
+  ```
+- Unquoted property names ([spec](https://spec.json5.org/#identifiers))
+  ```json5
+  {
+    unquoted: 'value',
+    'quoted-if-needed': true,
+  }
+  ```
+- More relaxed string syntax ([spec](https://spec.json5.org/#strings))
+  ```json5
+  {
+    single: 'strings',
+    multiline: 'can span\
+                multiple\
+                lines',
+  }
+  ```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34c53c8 and 10a6327.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • README.md (3 hunks)
  • package.json (1 hunks)
  • src/config/configLoad.ts (2 hunks)
  • tests/config/configLoad.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Test (windows-latest, 23.x)
  • GitHub Check: Test (windows-latest, 22.x)
  • GitHub Check: Test (windows-latest, 21.x)
  • GitHub Check: Test (windows-latest, 20.x)
  • GitHub Check: Test (windows-latest, 19.x)
  • GitHub Check: Test (windows-latest, 18.x)
  • GitHub Check: Build and run (windows-latest, 22.x)
  • GitHub Check: Test (windows-latest, 18.0.0)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
src/config/configLoad.ts (3)

3-3: LGTM!

The JSON5 import is correctly placed and follows the project's import style.


73-73: LGTM!

The change to use JSON5.parse aligns with the PR objective while maintaining backward compatibility.


78-78: LGTM!

The error message is correctly updated to reflect JSON5 parsing and maintains consistency with other error messages.

package.json (1)

79-79:

✅ Verification successful

Verify the json5 package version.

Let's check if there's a newer version available and if there are any security advisories.


🌐 Web query:

What is the latest version of json5?

💡 Result:

The latest stable release of JSON5 is v2.2.3, released on npm with a fix to ensure it's correctly marked as the "latest" version[1][4][7]. This update addressed an issue where older versions were incorrectly tagged as latest in package managers[1].

Key details about recent versions:

  • v2.2.3 (Current Latest):
    Fixes npm registry tagging[1][7]
  • v2.2.2:
    Patched a prototype pollution vulnerability related to __proto__ properties[1]
  • v2.2.1:
    Removed vulnerable minimist dependency (CVE-2021-44906)[1]

The project has seen regular maintenance updates since its major v2 release in 2020, which dropped Node.js v4 support and adopted native ES5 syntax[1]. For Python implementations like pyjson5 and json-five, separate versioning exists (e.g., json-five v1.x)[3][5].

Citations:


Dependency verified: json5 v2.2.3 is up-to-date.

The json5 dependency added at line 79 is using version "^2.2.3", which is confirmed as the current latest stable release with no outstanding security advisories.

README.md (2)

616-617: LGTM!

The trailing comma is correctly added and maintains consistent indentation.


628-629: LGTM!

The trailing commas are correctly added and maintain consistent indentation.

Also applies to: 635-636

@yamadashy yamadashy marked this pull request as ready for review February 22, 2025 06:24
@yamadashy yamadashy force-pushed the feat/config-trailing-commas branch from fe82fcb to e995a7d Compare February 22, 2025 06:37
@yamadashy yamadashy merged commit 3295800 into main Feb 22, 2025
53 checks passed
@yamadashy yamadashy deleted the feat/config-trailing-commas branch February 22, 2025 06:44
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.

Allow Trailing Commas in repomix.config.json
1 participant