Commit ba62c04
Add
## Description
Following the information provided in
[880](#880). This is an
implementation of the `pretty-format-json` hook.
The
[pretty-format-json](https://grep.app/search?f.path.pattern=.pre-commit-config.yaml&q=pretty-format-json)
has 1k grep.app hits. It's the final unimplemented hook used by
`airflow` as mentioned in [this
comment](#880 (comment)).
----
## Notes
- **Preserve JSON Order**
- Added the `preserve_order` feature to `serde_json`. This prevents
`serde` from automatically ordering JSON data, which is important for
comparisons with older implementations.
- This change does not appear to affect other tests/features.
- By default, `serde` uses a `BTreeMap` for `Object`. Enabling
`preserve_order` switches it to `IndexMap`.
- This keeps the sorting logic within the `sort-keys` argument.
- **Git-Style Diff with `similar`**
- Added the `similar` library to perform git-style diff checks.
- Binary size increase is minimal.
- Useful as a general utility and could be leveraged in other parts of
the project, maybe needed to be relocated?
- Added color highlighting to the diffs, improving readability compared
to original `pre-commit`.
```bash
cargo clean
cargo build --release
```
- Master branch: **8.49 MB**
- Feature branch: **8.55 MB**
- **+66,176 bytes** (**+0.74%**) increase from master to feature branch
_Q: why is my size so much smaller than both sizes mentioned
[here](#884 (comment)
-----
### Performance
Ran these commands on the `airflow` repository:
```bash
# old
pre-commit run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s
# Old prek implementation (python)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.03s
# New implementation (rust)
prek run pretty-format-json --all-files --verbose
Format JSON files........................................................Passed
- hook id: pretty-format-json
- duration: 0.00s
```
## Output
Old pre-commit:
<img width="601" height="376" alt="image"
src="https://github.com/user-attachments/assets/f0553015-24cf-4d23-98e8-2759f912c9b3"
/>
New:
<img width="707" height="430" alt="image"
src="https://github.com/user-attachments/assets/fa7ce303-caa9-4139-9e77-6e58db5f0725"
/>
Where both would autofix to the same:
<img width="349" height="304" alt="image"
src="https://github.com/user-attachments/assets/67baf526-787b-4aa6-a0fe-7859a2a5fb8b"
/>
---------
Co-authored-by: Felix Blom <70511386+Felix-Blom@users.noreply.github.com>
Co-authored-by: Jo <10510431+j178@users.noreply.github.com>pretty_format_json as builtin hook (#915)1 parent dbca904 commit ba62c04
File tree
10 files changed
+1288
-0
lines changed- crates/prek
- src/hooks
- builtin_hooks
- pre_commit_hooks
- tests
- docs
10 files changed
+1288
-0
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
362 | 364 | | |
363 | 365 | | |
364 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
365 | 379 | | |
366 | 380 | | |
367 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
73 | 79 | | |
| |||
0 commit comments