File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 87
87
entry : hooks/yaml/yaml-extension.sh
88
88
language : script
89
89
files : \.yml$
90
+ - id : yaml-sort
91
+ name : " yaml-sort: Style formatting"
92
+ description : " Ensure top-level nodes are sorted in YAML files"
93
+ entry : hooks/yaml/yaml-sort.sh
94
+ language : script
95
+ files : \.yaml$
90
96
# #####################
91
97
# Yalc related hook
92
98
- id : yalc-check
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ set -e
4
+
5
+ yaml_file=" $1 "
6
+
7
+ main () {
8
+ if [[ ! -f " $yaml_file " ]]; then
9
+ echo " Error: $yaml_file not found"
10
+ exit 1
11
+ fi
12
+ if ! command -v yq & > /dev/null; then
13
+ echo " Error: yq is required but not installed"
14
+ echo " Install with: brew install yq"
15
+ exit 1
16
+ fi
17
+
18
+ temp_file=$( mktemp)
19
+
20
+ yq eval ' sort_keys(.)' " $yaml_file " > " $temp_file "
21
+
22
+ if [[ $? -eq 0 ]]; then
23
+ mv " $temp_file " " $yaml_file "
24
+ echo " Sorted top-level keys in $yaml_file ."
25
+ git add " $yaml_file "
26
+ exit 0
27
+ else
28
+ echo " Error: Failed to sort YAML file"
29
+ rm -f " $temp_file "
30
+ exit 1
31
+ fi
32
+ }
33
+
34
+ if [[ " ${BASH_SOURCE[0]} " == " ${0} " ]]; then
35
+ main " $@ "
36
+ fi
You can’t perform that action at this time.
0 commit comments