Skip to content

Support formatting jsonschema.json - #917

Open
jviotti wants to merge 3 commits into
mainfrom
format-jsonschema-config
Open

jviotti wants to merge 3 commits into
mainfrom
format-jsonschema-config

Conversation

@jviotti

@jviotti jviotti commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

See: #916
Signed-off-by: Juan Cruz Viotti jv@jviotti.com

View guided diff

See: #916
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
WRITE expected_file_0.txt UNTIL EOF
{
"title": "My project",
"dependencies": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO to self: Maybe dependencies should be kept last?

@jviotti jviotti changed the title [WIP] Support formatting jsonschema.json Support formatting jsonschema.json Oct 10, 2026
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
jviotti marked this pull request as ready for review October 10, 2026 16:10
@augmentcode

augmentcode Bot commented Oct 10, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Adds configuration-file formatting without requiring a JSON Schema dialect.

  • Recognizes active configurations through discovery or `--configuration`.
  • Uses configuration ordering instead of schema/OpenAPI formatting.
  • Orders top-level and nested `lint` properties by predefined ranks.
  • Sorts set-like arrays and `resolve`/`dependencies` map keys.
  • Preserves `lint.rules` sequence order and existing values.
  • Places unknown properties after known properties alphabetically.
  • Supports in-place formatting, `--keep-ordering`, and indentation options.
  • Uses existing `--check` diagnostics, including JSON diff output.
  • Adds 13 CLI tests and documents `jsonschema fmt jsonschema.json`.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/command_fmt.cc
if (options.contains("keep-ordering")) {
sourcemeta::jsonschema::write_schema(entry.second, expected,
indentation, entry.roundtrip);
if (is_configuration) {

@augmentcode augmentcode Bot Oct 10, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you check the new branch at src/command_fmt.cc:316 with "ignore": ["./jsonschema.json"], a pattern already used in test/format/pass_cwd_config_no_path.clitest? for_each_json filters the explicitly requested configuration out at src/input.h:624–629 before this branch runs, so fmt jsonschema.json leaves it unchanged and fmt jsonschema.json --check reports success even when it is unformatted.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread src/command_fmt.cc Outdated
// goes on to order by the configuration format rather than by any dialect,
// so none of what tells a schema from the rest has a say over it
const auto is_configuration{configuration_path.has_value() &&
configuration_path.value() ==

@augmentcode augmentcode Bot Oct 10, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you check the comparison at src/command_fmt.cc:296–298 when jsonschema.json is a symlink to a same-directory config.json? for_each_json canonicalizes entry.resolution_base to the target, but Configuration::find returns the symlink path, so is_configuration is false and fmt jsonschema.json takes the schema path, failing without a default dialect or applying the wrong ordering.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@jviotti

jviotti commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

@cubic-dev-ai review

@jviotti I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 17 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/command_fmt.cc">

<violation number="1" location="src/command_fmt.cc:317">
P3: This message prints unconditionally, so a passing `jsonschema fmt --check jsonschema.json` in CI now always emits a line on stderr even without `--verbose`, polluting otherwise-silent check output. Guard it with `LOG_VERBOSE(options)` like the surrounding check/format progress logs, or emit it only in the non-check path.</violation>
</file>

<file name="src/utils.h">

<violation number="1" location="src/utils.h:200">
P2: Formatting a configuration file no longer validates it. Previously `fmt` always ran `read_configuration` -> blaze `Configuration::from_json` on the entry, so a malformed `jsonschema.json` (non-object root, or `extension`/`ignore`/`exclude` with non-string members) was rejected with a positioned `ConfigurationParseError`. The new `is_configuration` branch in `command_fmt.cc` skips that path entirely and just runs `format_configuration` plus `write_schema`, so such documents are silently reordered/rewritten (and `--check` passes on them). As a secondary risk, this `std::sort` compares heterogeneous `JSON` values via `JSON::operator<` (`sourcemeta::core::JSON::operator<`, vendor/core `json_value.h`), which core only defines for comparable values and which can throw, crashing `fmt` on arrays mixing types. Validate the document as a configuration (e.g., call `read_configuration` and surface `ConfigurationParseError`) before formatting it as one, or at minimum bail out of sorting when the array contains non-string elements.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/utils.h
return;
}

std::sort(value.as_array().begin(), value.as_array().end());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Formatting a configuration file no longer validates it. Previously fmt always ran read_configuration -> blaze Configuration::from_json on the entry, so a malformed jsonschema.json (non-object root, or extension/ignore/exclude with non-string members) was rejected with a positioned ConfigurationParseError. The new is_configuration branch in command_fmt.cc skips that path entirely and just runs format_configuration plus write_schema, so such documents are silently reordered/rewritten (and --check passes on them). As a secondary risk, this std::sort compares heterogeneous JSON values via JSON::operator< (sourcemeta::core::JSON::operator<, vendor/core json_value.h), which core only defines for comparable values and which can throw, crashing fmt on arrays mixing types. Validate the document as a configuration (e.g., call read_configuration and surface ConfigurationParseError) before formatting it as one, or at minimum bail out of sorting when the array contains non-string elements.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/utils.h, line 200:

<comment>Formatting a configuration file no longer validates it. Previously `fmt` always ran `read_configuration` -> blaze `Configuration::from_json` on the entry, so a malformed `jsonschema.json` (non-object root, or `extension`/`ignore`/`exclude` with non-string members) was rejected with a positioned `ConfigurationParseError`. The new `is_configuration` branch in `command_fmt.cc` skips that path entirely and just runs `format_configuration` plus `write_schema`, so such documents are silently reordered/rewritten (and `--check` passes on them). As a secondary risk, this `std::sort` compares heterogeneous `JSON` values via `JSON::operator<` (`sourcemeta::core::JSON::operator<`, vendor/core `json_value.h`), which core only defines for comparable values and which can throw, crashing `fmt` on arrays mixing types. Validate the document as a configuration (e.g., call `read_configuration` and surface `ConfigurationParseError`) before formatting it as one, or at minimum bail out of sorting when the array contains non-string elements.</comment>

<file context>
@@ -143,6 +148,115 @@ inline auto looks_like_test_document(const sourcemeta::core::JSON &document)
+    return;
+  }
+
+  std::sort(value.as_array().begin(), value.as_array().end());
+}
+
</file context>

Comment thread test/format/fail_check_configuration_file.clitest
Comment thread src/command_fmt.cc
sourcemeta::jsonschema::write_schema(entry.second, expected,
indentation, entry.roundtrip);
if (is_configuration) {
std::cerr << "Interpreting as a configuration file: " << entry.first

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This message prints unconditionally, so a passing jsonschema fmt --check jsonschema.json in CI now always emits a line on stderr even without --verbose, polluting otherwise-silent check output. Guard it with LOG_VERBOSE(options) like the surrounding check/format progress logs, or emit it only in the non-check path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/command_fmt.cc, line 317:

<comment>This message prints unconditionally, so a passing `jsonschema fmt --check jsonschema.json` in CI now always emits a line on stderr even without `--verbose`, polluting otherwise-silent check output. Guard it with `LOG_VERBOSE(options)` like the surrounding check/format progress logs, or emit it only in the non-check path.</comment>

<file context>
@@ -296,30 +312,43 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options)
-        sourcemeta::jsonschema::write_schema(entry.second, expected,
-                                             indentation, entry.roundtrip);
+      if (is_configuration) {
+        std::cerr << "Interpreting as a configuration file: " << entry.first
+                  << "\n";
+        if (options.contains("keep-ordering")) {
</file context>
Suggested change
std::cerr << "Interpreting as a configuration file: " << entry.first
LOG_VERBOSE(options) << "Interpreting as a configuration file: "
<< entry.first << "\n";

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 17 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread src/command_fmt.cc Outdated
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>

This branch has not been deployed

No deployments
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