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 | ||
42a9ebb8 DV |
8 | # See jshint/build/jshint-rhino.js for documentation on these parameters. |
9 | # devel defines logging globals (i.e. "console.log") | |
10 | # browser defines standard web browser globals (i.e. "document") | |
11 | # shadow disables warnings on multiple var definitions in one scope (i.e. two | |
12 | # loops with "var i") | |
13 | jsc_opts='maxerr:10000,devel:true,browser:true,shadow:true' | |
14 | rhino_opts='maxerr=10000,devel=true,browser=true,shadow=true' | |
758a629f | 15 | |
fefe0bfe DV |
16 | if [ $# -gt 1 ]; then |
17 | echo "Usage: $0 [file.js]" | |
18 | exit 1 | |
19 | fi | |
20 | ||
d3b49430 RK |
21 | RETURN_VALUE=0 |
22 | ||
fefe0bfe | 23 | if [ $# -eq 0 ]; then |
a6e8b4bb | 24 | files=$(ls dygraph*.js plugins/*.js | grep -v combined | grep -v dev.js| grep -v externs) |
fefe0bfe DV |
25 | else |
26 | files=$1 | |
27 | fi | |
758a629f DV |
28 | |
29 | if [ -e /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ]; then | |
30 | # use JSC (Safari/JavaScriptCore) to run JSHint -- much faster than Rhino. | |
31 | echo 'Running JSHint w/ JavaScriptCore (jsc)...' | |
32 | for file in $files; do | |
d3b49430 | 33 | ./jshint/env/jsc.sh $file $jsc_opts || RETURN_VALUE=1 |
758a629f DV |
34 | done |
35 | else | |
36 | # fall back to Rhino. | |
37 | echo 'Running JSHint w/ Rhino...' | |
38 | ||
39 | for FILE in $files; do | |
40 | LINT_RESULT=$(java -jar ./jsdoc-toolkit/java/classes/js.jar ./jshint/build/jshint-rhino.js $rhino_opts $FILE) | |
41 | ERRORS=$(echo ${LINT_RESULT} | egrep [^\s] -c) | |
42 | if [[ ${ERRORS} -ne 0 ]]; then | |
43 | echo "[jshint] Error(s) in ${FILE}:" | |
44 | printf "%s\n" "${LINT_RESULT}" | |
d3b49430 | 45 | RETURN_VALUE=1 |
758a629f DV |
46 | else |
47 | echo "[jshint] ${FILE} passed!" | |
48 | fi | |
49 | done | |
50 | fi | |
d3b49430 RK |
51 | |
52 | exit $RETURN_VALUE |