This repository has been archived by the owner on Apr 18, 2018. It is now read-only.
forked from jshint/jshint
-
Notifications
You must be signed in to change notification settings - Fork 2
/
jshint
executable file
·94 lines (81 loc) · 2.05 KB
/
jshint
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# A command-line frontent to jshint.
# We try to auto-detect a supported environment and use it.
#
# TODO: auto-detect the node jshint frontend
#
function quiet {
"$@" >/dev/null 2>&1
}
function abspath {
path="$1"
if [[ "$path" =~ ^/ ]]; then
echo $path
else
echo "$PWD/$path"
fi
}
function getOpts {
if [[ "$@" =~ (^| )--?h ]]; then
echo "usage: jshint ['{\"opt1\":true,\"opt2\":false}'] file1.js ..."
exit 0
fi
# heuristic for json argument: not a file and looks like json
if [[ ! -f "$1" && "$1" =~ \{.*\} ]]; then
jsopts="$1"
shift
else
jsopts="{}"
fi
# Make sure all input files are absolute paths.
index=0
for file in "$@"; do
files[$index]=`abspath "$file"`
let index+=1
done
}
function jsc {
interpreter="$1"
for file in "${files[@]}"; do
if [[ -r "$file" ]]; then
(cat "$file"; echo "EOF***") | "$interpreter" env/jsc.js -- "$HERE/jshint.js" "$jsopts" "$file"
else
echo "Error while reading:" "$file" >&2
fi
done
}
function smjs_interpret {
for file in "${files[@]}"; do
if [[ -r "$file" ]]; then
cat "$file" | smjs env/jsc.js "$HERE/jshint.js" "$jsopts" "$file"
else
echo "Error while reading:" "$file" >&2
fi
done
}
function main {
getOpts "$@"
cd $HERE
if quiet which d8; then
d8 env/d8.js -- "$jsopts" "${files[@]}"
elif quiet which smjs; then
smjs_interpret
elif quiet which jsc; then
jsc jsc
elif [ -e "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" ]; then
jsc /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
else
echo "Could not find any supported JavaScript environment. Looked for: d8 jsc smjs"
exit 1
fi
}
if [[ -L "$0" ]]; then
SCRIPT=`readlink $0`
else
SCRIPT="$0"
fi
HERE=`abspath $SCRIPT`
HERE=`dirname $HERE`
main "$@"
# vim:expandtab:sts=4: