Permalink
Browse files

made jsc work on osx, fixed spacing, changed error msg

  • Loading branch information...
1 parent 03e3eb0 commit b5169bf4269a60090894d8c260ac1a6478c6f14e Ken Struys committed Jan 10, 2012
Showing with 128 additions and 114 deletions.
  1. +33 −31 env/d8.js
  2. +36 −34 env/jsc.js
  3. +59 −49 jshint
View
@@ -16,37 +16,39 @@ if (typeof(JSHINT) === 'undefined') {
quit();
}
- var err, opts;
- var errorsFound = false;
- try {
- opts = JSON.parse(args[0]);
- } catch(err) {
- print( "Error while parsing arguments: '" + args[0] + "'" );
- quit();
- }
-
-
- for (var i = 1; i < args.length; i++) {
- try {
- print(args[i]);
- input = read(args[i]);
- } catch(err) {
- print("Error while reading:", args[i]);
- throw err;
- }
- if (!JSHINT(input, opts)) {
- if (JSHINT.errors.length) {
- print("ERROR: " + args[i]);
- errorsFound = true;
- }
-
- for (var j = 0; err = JSHINT.errors[j]; j++) {
- print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
- print('> ' + (err.evidence || '').replace(/\t/g, " "));
- print((new Array(err.character + 2)).join(' ') + '^');
- }
- }
- }
+ var err, opts;
+ var errorsFound = false;
+ try {
+ opts = JSON.parse(args[0]);
+ } catch(err) {
+ print( "Error while parsing arguments: '" + args[0] + "'" );
+ quit();
+ }
+
+
+ for (var i = 1; i < args.length; i++) {
+ try {
+ print(args[i]);
+ input = read(args[i]);
+ } catch(err) {
+ print("Error while reading:", args[i]);
+ throw err;
+ }
+ if (!JSHINT(input, opts)) {
+ if (JSHINT.errors.length) {
+ print("LINT ERROR: " + args[i]);
+ errorsFound = true;
+ }
+
+ for (var j = 0; err = JSHINT.errors[j]; j++) {
+ print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
+ print('> ' + (err.evidence || '').replace(/\t/g, " "));
+ print((new Array(err.character + 2)).join(' ') + '^');
+ }
+ }
+ }
quit(errorsFound ? -1 : 0);
})(arguments);
+
+// vim:expandtab:sw=2:sts=2
View
@@ -11,42 +11,44 @@ if (typeof(JSHINT) === 'undefined') {
}
(function(args){
- if (args.length < 2) {
- print('usage: cat file.js | jsc.js /path/to/jshint.js jsopts file.js');
- quit();
+ if (args.length < 2) {
+ print('usage: cat file.js | jsc.js /path/to/jshint.js jsopts file.js');
+ quit();
+ }
+
+ var err, opts;
+ try {
+ opts = JSON.parse(args[1]);
+ } catch(err) {
+ print( "Error while parsing arguments: '" + args[1] + "'" );
+ quit();
+ }
+
+ var line = readline();
+ var input = "";
+ while ( line !== null && line !== undefined && line !== 'EOF***') {
+ input += line + '\n';
+ line = readline();
+ }
+
+ if (!JSHINT(input, opts)) {
+ if (JSHINT.errors.length) {
+ print("LINT ERROR: " + args[2]);
+ }
+
+ for (var j = 0; err = JSHINT.errors[j]; j++) {
+ print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
+ print('> ' + (err.evidence || '').replace(/\t/g, " "));
+ print((new Array(err.character + 2)).join(' ') + '^');
}
+ }
- var err, opts;
- try {
- opts = JSON.parse(args[1]);
- } catch(err) {
- print( "Error while parsing arguments: '" + args[1] + "'" );
- quit();
- }
-
- var line = readline();
- var input = "";
- while ( line !== null && line !== undefined) {
- input += line + '\n';
- line = readline();
- }
-
- if (!JSHINT(input, opts)) {
- if (JSHINT.errors.length) {
- print("ERROR: " + args[2]);
- }
-
- for (var j = 0; err = JSHINT.errors[j]; j++) {
- print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
- print('> ' + (err.evidence || '').replace(/\t/g, " "));
- print((new Array(err.character + 2)).join(' ') + '^');
- }
- }
-
- if (JSHINT.errors.length) {
- quit(-1);
- }
+ if (JSHINT.errors.length) {
+ quit(-1);
+ }
- quit();
+ quit();
})(arguments);
+
+// vim:expandtab:sw=2:sts=2
View
@@ -7,74 +7,84 @@
#
function quiet {
- "$@" >/dev/null 2>&1
+ "$@" >/dev/null 2>&1
}
function abspath {
- path="$1"
- if [[ "$path" =~ ^/ ]]; then
- echo $path
- else
- echo "$PWD/$path"
- fi
+ 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
+ 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
+ # 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
+ interpreter="$1"
- for file in "${files[@]}"; do
- if [[ -r "$file" ]]; then
- cat "$file" | "$interpreter" env/jsc.js "$HERE/jshint.js" "$jsopts" "$file"
- else
- echo "Error while reading:" "$file"
- fi
- done
+ 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"
+ fi
+ done
+}
+
+function smjs {
+ 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"
+ fi
+ done
}
function main {
- getOpts "$@"
- cd $HERE
+ getOpts "$@"
+ cd $HERE
- if quiet which d8; then
- d8 env/d8.js -- "$jsopts" "${files[@]}"
- elif quiet which smjs; then
- jsc smjs
- 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 quiet which d8; then
+ d8 env/d8.js -- "$jsopts" "${files[@]}"
+ elif quiet which smjs; then
+ smjs
+ 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`
+ SCRIPT=`readlink $0`
else
- SCRIPT="$0"
+ SCRIPT="$0"
fi
HERE=`abspath $SCRIPT`
HERE=`dirname $HERE`

0 comments on commit b5169bf

Please sign in to comment.