Skip to content

feat(config): support comments in JSON configuration files#22

Open
sunteya wants to merge 1 commit intovtemian:mainfrom
sunteya:feat/support-jsonc-config
Open

feat(config): support comments in JSON configuration files#22
sunteya wants to merge 1 commit intovtemian:mainfrom
sunteya:feat/support-jsonc-config

Conversation

@sunteya
Copy link

@sunteya sunteya commented Feb 5, 2026

Summary

Introduced jsonc-parser to replace the standard JSON.parse method, enabling support for comments in configuration files.

Motivation

Configuration files (such as opencode.json, micode.json, and fragments.json) often benefit from comments for documentation purposes or for temporarily disabling specific settings. The standard JSON parser does not support comments, which limits the usability of these config files.

Changes

  • Added jsonc-parser as a dependency.
  • Updated src/config-loader.ts to parse opencode.json and micode.json using Jsonc.parse.
  • Updated src/hooks/fragment-injector.ts to parse fragments.json using Jsonc.parse.

Verification

  1. Add a comment (e.g., // test comment) to your opencode.json or micode.json file.
  2. Run the application.
  3. Verify that the configuration loads successfully without throwing a parsing error.

Summary by cubic

Enable comments in JSON config files by switching parsing to jsonc-parser. Users can add inline comments in opencode.json, micode.json, and fragments.json without parse errors.

  • New Features

    • Use Jsonc.parse in config-loader and fragment-injector to read opencode.json, micode.json, and fragments.json with comments.
  • Dependencies

    • Add jsonc-parser.

Written for commit fc08267. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/config-loader.ts">

<violation number="1" location="src/config-loader.ts:34">
P2: Jsonc.parse is fault-tolerant and won’t throw on invalid JSON; without checking its errors list, malformed or empty/comment-only configs can bypass the try/catch and be treated as valid, changing the error-handling semantics from returning null to returning undefined/partial configs.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

const configPath = join(baseDir, "opencode.json");
const content = readFileSync(configPath, "utf-8");
return JSON.parse(content) as OpencodeConfig;
return Jsonc.parse(content) as OpencodeConfig;
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

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

P2: Jsonc.parse is fault-tolerant and won’t throw on invalid JSON; without checking its errors list, malformed or empty/comment-only configs can bypass the try/catch and be treated as valid, changing the error-handling semantics from returning null to returning undefined/partial configs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/config-loader.ts, line 34:

<comment>Jsonc.parse is fault-tolerant and won’t throw on invalid JSON; without checking its errors list, malformed or empty/comment-only configs can bypass the try/catch and be treated as valid, changing the error-handling semantics from returning null to returning undefined/partial configs.</comment>

<file context>
@@ -30,7 +31,7 @@ function loadOpencodeConfig(configDir?: string): OpencodeConfig | null {
     const configPath = join(baseDir, "opencode.json");
     const content = readFileSync(configPath, "utf-8");
-    return JSON.parse(content) as OpencodeConfig;
+    return Jsonc.parse(content) as OpencodeConfig;
   } catch {
     return null;
</file context>
Suggested change
return Jsonc.parse(content) as OpencodeConfig;
const errors: { error: number }[] = [];
const parsed = Jsonc.parse(content, errors);
if (errors.length > 0) {
return null;
}
return parsed as OpencodeConfig;
Fix with Cubic

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