forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.sh
executable file
·54 lines (46 loc) · 1.25 KB
/
lint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
PERL=`which perl`
if [ $? -ne 0 ]; then
echo "perl is required to run this script"
exit 69; # EX_UNAVAILABLE
fi
JQ=`which jq`
if [ $? -ne 0 ]; then
echo "jq is required to run this script"
exit 69; # EX_UNAVAILABLE
fi
LINTER=`dirname $(readlink -f "$0")`/format/format.pl
if [ ! -f $LINTER -o ! -r $LINTER ]; then
echo "Missing linter"
exit 70; # EX_SOFTWARE
fi
CONFIG=`dirname $(readlink -f "$0")`/../json_whitelist
if [ ! -f $CONFIG -o ! -r $CONFIG ]; then
echo "Missing json_whitelist"
exit 70; # EX_SOFTWARE
fi
for file in "$@"; do
# check file exists and is readable
if [ ! -f $file -o ! -r $file ]; then
echo "File not found: $file"
exit 66; # EX_NOINPUT
fi
# Check validity via JQ
$JQ '.' $file >/dev/null;
if [ $? -ne 0 ]; then
echo "Syntax error in $file"
exit 65; # EX_DATAERR
fi
# Lint to canonical format
output=$($PERL $LINTER $file)
if [ $? -ne 0 ]; then
echo "Invalid definition in $file"
exit 65; # EX_DATAERR
fi
# Update if not in canonical form
echo "$output" | diff -q $file - > /dev/null
if [ $? -ne 0 ]; then
echo "Fixed JSON regressions in $file"
echo "$output" > $file
fi
done