From d368e0eaf649b61d98c1aa29d6ab0d38e278e3fe Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Mon, 28 Feb 2022 16:31:56 -0800 Subject: [PATCH] Add json sorting pre-commit hook --- .pre-commit-config.yaml | 7 +++++++ scripts/sort-json.sh | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100755 scripts/sort-json.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee5cc66..339ae3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,10 @@ repos: rev: v0.11.3 hooks: - id: stylua + - repo: local + hooks: + - id: sort-json + name: sort json files with jq + language: script + entry: ./scripts/sort-json.sh + files: "(\\.json$|^neovim/packer_snapshots/)" diff --git a/scripts/sort-json.sh b/scripts/sort-json.sh new file mode 100755 index 0000000..ddd7157 --- /dev/null +++ b/scripts/sort-json.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash +set -e + +for f in "$@"; do + jq --sort-keys --monochrome-output . "$f" > "$f.tmp" + mv "$f.tmp" "$f" +done