From aeab45ad7f22c0f6c3a29e1691731f40320cedb5 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 15 Sep 2015 12:48:23 +0200 Subject: [PATCH] dib-lint: validate json/yaml files Look for files .yaml and pkg-map configurations, and try to load them either as json or yaml. This way, invalid ones can be detected before they are committed unnoticed. Also, exclude .yaml files from being searched while checking bash and python scripts. Change-Id: I2478837cfe66929ae1b0d7dd96e049773a35e11c --- bin/dib-lint | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bin/dib-lint b/bin/dib-lint index 31cbd4d8..a9b2df44 100755 --- a/bin/dib-lint +++ b/bin/dib-lint @@ -64,6 +64,7 @@ trap "rm -rf $TMPDIR" EXIT for i in $(find elements -type f \ -not -name \*~ \ -not -name \*.rst \ + -not -name \*.yaml \ -not -name \*.py \ -not -name \*.pyc); do exclusions=("$(parse_exclusions $i)") @@ -151,4 +152,27 @@ md_docs=$(find elements -name '*.md') if [ -n "$md_docs" ]; then error ".md docs found: $md_docs" fi + +for i in $(find elements -name '*.yaml' \ + -o \( -name pkg-map -type f -a \! -executable \)); do + 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)" + if ! python -c "$py_check"; then + error "$i is not a valid yaml/json file" + fi +done + exit $rc