Skip to content

Support formatting in the lint command using --format#642

Merged
jviotti merged 1 commit intomainfrom
lint-formatting
Feb 3, 2026
Merged

Support formatting in the lint command using --format#642
jviotti merged 1 commit intomainfrom
lint-formatting

Conversation

@jviotti
Copy link
Member

@jviotti jviotti commented Feb 3, 2026

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

@augmentcode
Copy link

augmentcode bot commented Feb 3, 2026

🤖 Augment PR Summary

Summary: This PR extends the jsonschema lint command with an optional schema formatting step via --format/-m, aligning lint auto-fixes with canonical formatting.

Changes:

  • Added --format/-m to lint to format schemas in-place after applying fixes.
  • Added --keep-ordering/-k to keep original key ordering while still prettifying output.
  • Introduced option conflict checks: --format requires --fix, and --keep-ordering requires --format.
  • Implemented formatting by running sourcemeta::core::format (unless keeping ordering), then pretty-printing and writing only when file contents differ.
  • Updated CLI help text and lint documentation to reflect the new flags and their intended usage.
  • Added multiple new shell-based regression tests and wired them into test/CMakeLists.txt covering success cases and failure modes.

Technical Notes: Formatting is only available in fix mode (no “check-only” behavior for lint formatting), and YAML inputs still error when --fix is used.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestions posted.

Fix All in Augment

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

**The `--fix/-f` option is not supported when passing YAML schemas.**

**The `--format/-m` option requires `--fix/-f` to be set and is not supported
for YAML schemas.** Use `--keep-ordering/-k` with `--format/-m` to preserve
Copy link

Choose a reason for hiding this comment

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

The docs mention using --keep-ordering/-k with --format/-m, but the implementation treats it as a hard requirement (it errors if --keep-ordering is set without --format). Consider stating this explicitly (e.g., “requires --format”).

Severity: low

Fix This in Augment

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

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.

3 issues found across 12 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="test/lint/fail_lint_keep_ordering_without_format.sh">

<violation number="1" location="test/lint/fail_lint_keep_ordering_without_format.sh:25">
P2: Add a JSON variant of this failure test. After the text assertion, run the same command with --json and verify the structured error output so JSON error reporting stays consistent.

(Based on your team's feedback about adding JSON variants for failure test cases.) [FEEDBACK_USED]</violation>
</file>

<file name="test/lint/fail_lint_fix_format_unfixable.sh">

<violation number="1" location="test/lint/fail_lint_fix_format_unfixable.sh:19">
P2: Failing tests are expected to include a JSON variant that exercises `--json` output. Add a JSON version of this test (or extend this script) that runs `lint ... --json` and asserts on the structured error output.

(Based on your team's feedback about adding JSON variants for failure test cases.) [FEEDBACK_USED]</violation>
</file>

<file name="test/lint/fail_lint_format_yaml.sh">

<violation number="1" location="test/lint/fail_lint_format_yaml.sh:15">
P2: Add a `--json` variant of this failure test so structured error output is validated alongside the text output.

(Based on your team's feedback about adding JSON variants for failure test cases.) [FEEDBACK_USED]</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.

error: The --keep-ordering option requires --format to be set
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
Copy link

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

Choose a reason for hiding this comment

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

P2: Add a JSON variant of this failure test. After the text assertion, run the same command with --json and verify the structured error output so JSON error reporting stays consistent.

(Based on your team's feedback about adding JSON variants for failure test cases.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/lint/fail_lint_keep_ordering_without_format.sh, line 25:

<comment>Add a JSON variant of this failure test. After the text assertion, run the same command with --json and verify the structured error output so JSON error reporting stays consistent.

(Based on your team's feedback about adding JSON variants for failure test cases.) </comment>

<file context>
@@ -0,0 +1,25 @@
+error: The --keep-ordering option requires --format to be set
+EOF
+
+diff "$TMP/stderr.txt" "$TMP/expected.txt"
</file context>
Fix with Cubic

}
EOF

"$1" lint "$TMP/schema.json" --fix --format && CODE="$?" || CODE="$?"
Copy link

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

Choose a reason for hiding this comment

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

P2: Failing tests are expected to include a JSON variant that exercises --json output. Add a JSON version of this test (or extend this script) that runs lint ... --json and asserts on the structured error output.

(Based on your team's feedback about adding JSON variants for failure test cases.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/lint/fail_lint_fix_format_unfixable.sh, line 19:

<comment>Failing tests are expected to include a JSON variant that exercises `--json` output. Add a JSON version of this test (or extend this script) that runs `lint ... --json` and asserts on the structured error output.

(Based on your team's feedback about adding JSON variants for failure test cases.) </comment>

<file context>
@@ -0,0 +1,31 @@
+}
+EOF
+
+"$1" lint "$TMP/schema.json" --fix --format && CODE="$?" || CODE="$?"
+test "$CODE" = "2" || exit 1
+
</file context>
Fix with Cubic

@jviotti jviotti force-pushed the lint-formatting branch 3 times, most recently from 77939c6 to 043ab1e Compare February 3, 2026 13:51
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti jviotti merged commit 2f656f4 into main Feb 3, 2026
24 of 25 checks passed
@jviotti jviotti deleted the lint-formatting branch February 3, 2026 14:29
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