allow lint.sh to take a file as a command-line argument
[dygraphs.git] / lint.sh
CommitLineData
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
8jsc_opts='maxerr:10000,devel:true,browser:true'
9rhino_opts='maxerr=10000,devel=true,browser=true'
10
fefe0bfe
DV
11if [ $# -gt 1 ]; then
12 echo "Usage: $0 [file.js]"
13 exit 1
14fi
15
16if [ $# -eq 0 ]; then
17 files=$(ls dygraph*.js plugins/*.js | grep -v combined | grep -v dev.js)
18else
19 files=$1
20fi
758a629f
DV
21
22if [ -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
28else
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
42fi