Skip to content

schemas: Indent .lock.json for readability - #231

Open
Bham06 wants to merge 1 commit into
crossplane:mainfrom
Bham06:indent-schema-lock-json
Open

schemas: Indent .lock.json for readability#231
Bham06 wants to merge 1 commit into
crossplane:mainfrom
Bham06:indent-schema-lock-json

Conversation

@Bham06

@Bham06 Bham06 commented Jul 28, 2026

Copy link
Copy Markdown

Description of your changes

schemas/.lock.json was written on a single line, which is hard to read and
causes avoidable merge conflicts whenever more than one dependency changes.

This writes the lock file with json.MarshalIndent (two-space indent) plus a
trailing newline, so each dependency is on its own line. Reads are unaffected:
getLock decodes with a json.Decoder, and indented JSON is still valid. Map
keys marshal in sorted order, so the output is deterministic.

Fixes #168

I have:

  • Read and followed Crossplane's contribution process.
  • Run ./nix.sh flake check to ensure this PR is ready for review. Ran go test ./internal/schemas/manager/... ./internal/dependency/..., go vet, and gofmt, and reviewed the change against .golangci.yml; relied on CI for the full flake check.
  • Added or updated unit tests. (Added TestUpdateLockIsIndented.)
  • Linked a PR or a docs tracking issue to document this change. Internal on-disk lock file format; no user-facing docs.
  • Added backport release-x.y labels to auto-backport this PR. Minor readability change; left to maintainer discretion.

The schema lock file (.lock.json) was written on a single line, making it
hard to read and prone to merge conflicts whenever more than one
dependency changed.

Write it with json.MarshalIndent (two-space indent) and a trailing
newline so each dependency is on its own line. Reads are unaffected;
getLock decodes the file with a json.Decoder and indented JSON remains
valid.

Fixes crossplane#168

Signed-off-by: Bham06 <heu319@student.bham.ac.uk>
@Bham06
Bham06 marked this pull request as ready for review July 29, 2026 09:54
@Bham06
Bham06 requested review from a team, jcogilvie and tampakrap as code owners July 29, 2026 09:54
@Bham06
Bham06 requested review from bobh66 and removed request for a team July 29, 2026 09:54
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

updateLock now writes schema locks as indented JSON with a trailing newline. A unit test verifies the exact formatted output for multiple package entries.

Changes

Schema lock formatting

Layer / File(s) Summary
Formatted lock output and validation
internal/schemas/manager/manager.go, internal/schemas/manager/manager_test.go
updateLock writes two-space-indented JSON with a trailing newline, and a unit test verifies deterministic output for two package entries.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: adamwg

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, under 72 characters, and clearly describes the lock-file indentation change.
Description check ✅ Passed The description matches the code changes and explains the readability and merge-conflict motivation.
Linked Issues check ✅ Passed The PR implements #168 by pretty-printing schemas/.lock.json and adding a test for the new format.
Out of Scope Changes check ✅ Passed The changes stay focused on lock-file formatting and the supporting test, with no obvious unrelated edits.
Breaking Changes ✅ Passed No files under apis/** or cmd/** changed; the PR only updates internal/schemas/manager, so the breaking-change rule isn’t triggered.
Feature Gate Requirement ✅ Passed The patch only changes internal schemas lock-file formatting and tests; no apis/** changes or new experimental behavior/feature-gate code appear.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/schemas/manager/manager_test.go (1)

174-204: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the required table-driven test structure.

This test covers the right behavior, but *_test.go files must use table-driven cases with an args/want shape. Please move the lock input and expected serialized output into a test case and run it through t.Run; cmp.Diff is already appropriate here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/schemas/manager/manager_test.go` around lines 174 - 204, The
TestUpdateLockIsIndented test must use the required table-driven args/want
structure. Refactor the test to place the lock input and expected serialized
output in a test case, iterate over the cases with t.Run, and keep the existing
updateLock, file-read, and cmp.Diff assertions within the case execution.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/schemas/manager/manager_test.go`:
- Around line 174-204: The TestUpdateLockIsIndented test must use the required
table-driven args/want structure. Refactor the test to place the lock input and
expected serialized output in a test case, iterate over the cases with t.Run,
and keep the existing updateLock, file-read, and cmp.Diff assertions within the
case execution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3db44ebd-3ab6-4dbf-b450-462329392d67

📥 Commits

Reviewing files that changed from the base of the PR and between 6f65d73 and f9b2f19.

📒 Files selected for processing (2)
  • internal/schemas/manager/manager.go
  • internal/schemas/manager/manager_test.go

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.

Indent schemas/.lock.json

1 participant