fix(pre-commit): keep key order in pretty-format-json so apm-owned JSON survives #146
Reference in New Issue
Block a user
Delete Branch "fix/pretty-json-no-sort-keys-102"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
--no-sort-keystopretty-format-json. apm emits insertion order andapm audit --cidiffs its output byte-for-byte, so the formatter's default key sort rewrites apm-owned JSON into a form apm would never produce and the pre-push gate reports drift on a file with an emptygit diff..claude/settings.jsonand.claude/apm-hooks.jsonnow round-trip untouched, so both leave the hook'sexclude:..claude-plugin/marketplace.jsonstays excluded: it carries literal em dashes, and the formatter re-escapes them as ASCII unicode escapes.docs/spec/gates.mdsection and theLESSONS.md2026-08-14 entry, both of which told readers to add excludes.Why this instead of the gate proposed in #102
Analysis of #102 on current
mainfound it partly stale: the exclude list is 3 paths (not 16), three of the five precedent gates were deleted in #135, and only 5 tracked JSON files exist. Removing the cause is smaller than policing it: acheck-formatter-scope-syncgate would be ~250 lines plus a test and agates.mdentry, and would still need a hand-maintained list of tool-owned paths becauseapm.lock.yamldoes not enumeratesettings.json,apm-hooks.json,marketplace.jsonor itself. No ADR: it is a config choice with no design tension.No dedicated regression test is added.
apm-audit-ciat pre-push already fails if the flag is dropped, so a test would only improve the diagnosis (see the second commit, which removes one that was first included).Test plan
settings.json,apm-hooks.jsonandmarketplace.jsonare rewritten by the formatter; with the flag,settings.jsonandapm-hooks.jsonround-trip byte-identical..claude/settings.jsonmakesapm audit --cifail with drift; the committed file passes.apm audit --ci,apm pack --check-clean,check-useless-excludes, others).Out of scope / follow-up
--no-ensure-asciiwould letmarketplace.jsonround-trip and remove the last exclude, but it changes output for every JSON file. Left for a separate decision.apm-audit-cidrift, not by a derived gate.🤖 Generated with Claude Code
https://claude.ai/code/session_01KkT7RSDwDbmrM9T34b6sTi
Dropped
tests/test-pretty-json-tool-owned.shin18fbdbc. It was about 100 lines of bash and Python, and it depended on the pre-commit cache. It would only have improved the diagnosis, becauseapm-audit-cialready fails at pre-push if--no-sort-keysis removed (I confirmed a key-sorted.claude/settings.jsonfailsapm audit --ciwith drift).The PR is now the one-line flag, the exclude shrink, the config comment, and the
gates.mdandLESSONS.mdupdates. The PR body is updated to match, and the comment,gates.mdandLESSONS.mdno longer reference the test. Pre-push gates pass on the branch.Co-Authored-By: Claude Code noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01KkT7RSDwDbmrM9T34b6sTi