Commit | Line | Data |
---|---|---|
758a629f | 1 | #!/bin/bash |
fefe0bfe DV |
2 | # |
3 | # Usage: | |
4 | # ./lint.sh [file.js] | |
5 | # | |
6 | # The zero-argument form lints everything. | |
7 | ||
758a629f DV |
8 | jsc_opts='maxerr:10000,devel:true,browser:true' |
9 | rhino_opts='maxerr=10000,devel=true,browser=true' | |
10 | ||
fefe0bfe DV |
11 | if [ $# -gt 1 ]; then |
12 | echo "Usage: $0 [file.js]" | |
13 | exit 1 | |
14 | fi | |
15 | ||
16 | if [ $# -eq 0 ]; then | |
17 | files=$(ls dygraph*.js plugins/*.js | grep -v combined | grep -v dev.js) | |
18 | else | |
19 | files=$1 | |
20 | fi | |
758a629f DV |
21 | |
22 | if [ -e /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ]; then | |
23 | # use JSC (Safari/JavaScriptCore) to run JSHint -- much faster than Rhino. | |
24 | echo 'Running JSHint w/ JavaScriptCore (jsc)...' | |
25 | for file in $files; do | |
26 | ./jshint/env/jsc.sh $file $jsc_opts | |
27 | done | |
28 | else | |
29 | # fall back to Rhino. | |
30 | echo 'Running JSHint w/ Rhino...' | |
31 | ||
32 | for FILE in $files; do | |
33 | LINT_RESULT=$(java -jar ./jsdoc-toolkit/java/classes/js.jar ./jshint/build/jshint-rhino.js $rhino_opts $FILE) | |
34 | ERRORS=$(echo ${LINT_RESULT} | egrep [^\s] -c) | |
35 | if [[ ${ERRORS} -ne 0 ]]; then | |
36 | echo "[jshint] Error(s) in ${FILE}:" | |
37 | printf "%s\n" "${LINT_RESULT}" | |
38 | else | |
39 | echo "[jshint] ${FILE} passed!" | |
40 | fi | |
41 | done | |
42 | fi |