Last active
August 29, 2015 14:01
-
-
Save tkuchiki/1f2569d56a2d5818919d to your computer and use it in GitHub Desktop.
jsonlint で json の syntax check を行う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
echo -e "\nUsage: $(basename $0) DIR [DIR ...]\n" | |
echo -e " json syntax checker(require jsonlint)\n" | |
exit 1 | |
fi | |
if type jsonlint > /dev/null 2>&1 && [ $? -ne 0 ]; then | |
echo "jsonlint is required. [npm install -g jsonlint]" | |
exit 1 | |
fi | |
WHITE='\033[0m' | |
GREEN='\033[32m' | |
RED='\033[31m' | |
OK_CNT=0 | |
ERR_CNT=0 | |
for DIR in "$@"; do | |
for _DIR in $(find $DIR -type f); do | |
FILENAME=$(basename $_DIR) | |
[ ${FILENAME##*.} != "json" ] && continue | |
echo "## ${_DIR}" | |
jsonlint -q $_DIR | |
if [ $? -eq 0 ]; then | |
echo -e "${GREEN}syntax ok${WHITE}" | |
OK_CNT=$((1 + $OK_CNT)) | |
else | |
echo -e "${RED}syntax error${WHITE}" | |
ERR_CNT=$((1 + $ERR_CNT)) | |
fi | |
done | |
done | |
echo | |
echo -e "${GREEN}ok: ${OK_CNT}${WHITE}" | |
echo -e "${RED}error: ${ERR_CNT}${WHITE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment