Split YAML & JSON parsing
It turns out that invalid JSON can be valid YAML ... thus if you mess up a pkg-map file that still works as a YAML file dib-lint will let it pass, but when pkg-map later tries to open it as a JSON file, it fails. Parse each type separately to catch these problems. Change-Id: Ib3985e7d1599ed6bf3b7a73b786a53177b71fae0
This commit is contained in:
parent
b388b20f99
commit
8b4a5e9919
36
bin/dib-lint
36
bin/dib-lint
@ -176,27 +176,35 @@ if ! excluded mddocs; then
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Checking YAML & JSON parsing"
|
||||
|
||||
for i in $(find elements -name '*.yaml' \
|
||||
-o \( -name pkg-map -type f -a \! -executable \)); do
|
||||
echo "Checking YAML parsing..."
|
||||
for i in $(find elements -type f -name '*.yaml'); do
|
||||
echo "Parsing $i"
|
||||
py_check="
|
||||
import json
|
||||
import yaml
|
||||
import sys
|
||||
try:
|
||||
objs = json.load(open('$i'))
|
||||
sys.exit(0)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
objs = yaml.load(open('$i'))
|
||||
sys.exit(0)
|
||||
except yaml.parser.ParserError:
|
||||
pass
|
||||
sys.exit(1)"
|
||||
sys.exit(1)
|
||||
"
|
||||
if ! python -c "$py_check"; then
|
||||
error "$i is not a valid yaml/json file"
|
||||
error "$i is not a valid YAML file"
|
||||
fi
|
||||
done
|
||||
echo "Checking pkg-map files..."
|
||||
for i in $(find elements -type f \
|
||||
-name 'pkg-map' -a \! -executable); do
|
||||
echo "Parsing $i"
|
||||
py_check="
|
||||
import json
|
||||
import sys
|
||||
try:
|
||||
objs = json.load(open('$i'))
|
||||
except ValueError:
|
||||
sys.exit(1)
|
||||
"
|
||||
if ! python -c "$py_check"; then
|
||||
error "$i is not a valid JSON file"
|
||||
fi
|
||||
done
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user