File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ the type of file(s) you want to lint:
4444
4545 $ which node # returns a path if it is installed properly.
4646
47+ * If you want to syntax-lint JSON files, you will need to install
48+ [ jsonlint] ( https://github.com/PagerDuty/jsonlint#installation ) .
49+
50+ $ which jsonlint # returns a path if it is installed properly.
51+
4752 * If you want to syntax-lint PHP files, you will need to
4853 [ install PHP] ( http://php.net/manual/install.php ) .
4954
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ case "${1}" in
3131 ;;
3232
3333 * )
34- for file in $( git diff-index --cached --name-only HEAD | grep -E ' \.(js|json )' ) ; do
34+ for file in $( git diff-index --cached --name-only HEAD | grep -E ' \.(js)' ) ; do
3535 test_file " ${file} "
3636 done
3737 ;;
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # shellcheck disable=SC2034
4+ GREP_OPTIONS=" "
5+
6+ function test_file {
7+ file=" ${1} "
8+
9+ if [ ! -f " ${file} " ] ; then
10+ return
11+ fi
12+
13+ if which -s node ; then
14+ echo " Running JSON syntax lint..."
15+
16+ # Set -e before and +e after for _required_ linters (i.e.: that will prevent
17+ # commit, e.g.: syntax linters).
18+ # Set +e before and -e after for _optional_ linters (i.e.: that will only
19+ # output messages upon commit, e.g.: style linters).
20+ set -e
21+ jsonlint -c " $file "
22+ set +e
23+ else
24+ echo " Can't run JSON syntax linter because the jsonlint executable isn't in the PATH."
25+ fi
26+ }
27+
28+ case " ${1} " in
29+ --about )
30+ echo " JSON syntax lint."
31+ ;;
32+
33+ * )
34+ for file in $( git diff-index --cached --name-only HEAD | grep -E ' \.(json)' ) ; do
35+ test_file " ${file} "
36+ done
37+ ;;
38+ esac
You can’t perform that action at this time.
0 commit comments