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