forked from danvk/dygraphs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.sh
executable file
·49 lines (43 loc) · 1.42 KB
/
lint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Usage:
# ./lint.sh [file.js]
#
# The zero-argument form lints everything.
# See jshint/build/jshint-rhino.js for documentation on these parameters.
# devel defines logging globals (i.e. "console.log")
# browser defines standard web browser globals (i.e. "document")
# shadow disables warnings on multiple var definitions in one scope (i.e. two
# loops with "var i")
jsc_opts='maxerr:10000,devel:true,browser:true,shadow:true'
rhino_opts='maxerr=10000,devel=true,browser=true,shadow=true'
if [ $# -gt 1 ]; then
echo "Usage: $0 [file.js]"
exit 1
fi
if [ $# -eq 0 ]; then
files=$(ls dygraph*.js plugins/*.js | grep -v combined | grep -v dev.js)
else
files=$1
fi
jshint_opts="shadow=false"
if [ -e /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ]; then
# use JSC (Safari/JavaScriptCore) to run JSHint -- much faster than Rhino.
echo 'Running JSHint w/ JavaScriptCore (jsc)...'
for file in $files; do
./jshint/env/jsc.sh $file $jsc_opts
done
else
# fall back to Rhino.
echo 'Running JSHint w/ Rhino...'
for FILE in $files; do
LINT_RESULT=$(java -jar ./jsdoc-toolkit/java/classes/js.jar ./jshint/build/jshint-rhino.js $rhino_opts $FILE)
ERRORS=$(echo ${LINT_RESULT} | egrep [^\s] -c)
if [[ ${ERRORS} -ne 0 ]]; then
echo "[jshint] Error(s) in ${FILE}:"
printf "%s\n" "${LINT_RESULT}"
else
echo "[jshint] ${FILE} passed!"
fi
done
fi