sbin/res/jslint-wrapper.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 97 62612c69699f
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
97
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     1
/* source comes from a similar jquery script */
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     2
/* run it like this :  java -jar rhino.jar jslint-wrapper.js file.js */
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     3
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     4
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     5
if (arguments.length == 1) {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     6
  jslint = "jslint.js"
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     7
  srcfile = arguments[0];
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     8
} else if (arguments.length != 2) {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
     9
  print("jslint-wrapper jslint.js myfile.js");
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    10
  quit();
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    11
} else {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    12
  var jslint = arguments[0];
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    13
  var srcfile = arguments[1];
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    14
}
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    15
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    16
src = readFile(srcfile, "utf8");
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    17
load(jslint);
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    18
  
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    19
JSLINT(src, { browser: true, forin: true, maxerr: 5 });
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    20
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    21
//All of the following are known issues that we think are 'ok'
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    22
//(in contradiction with JSLint) more information here:
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    23
//http://docs.jquery.com/JQuery_Core_Style_Guidelines
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    24
var ok = {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    25
	"Expected an identifier and instead saw 'undefined' (a reserved word).": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    26
	"Use '===' to compare with 'null'.": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    27
	"Use '!==' to compare with 'null'.": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    28
	"Expected an assignment or function call and instead saw an expression.": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    29
	"Expected a 'break' statement before 'case'.": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    30
	"'e' is already defined.": true,
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    31
  "Expected exactly one space between 'function' and '('": true
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    32
};
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    33
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    34
var e = JSLINT.errors, found = 0, w;
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    35
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    36
for ( var i = 0; i < e.length; i++ ) {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    37
	w = e[i];
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    38
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    39
	if ( !ok[ w.reason ] ) {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    40
		found++;
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    41
		print( "\n" + w.evidence + "\n" );
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    42
		print( "    Problem at line " + w.line + " character " + w.character + ": " + w.reason );
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    43
	}
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    44
}
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    45
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    46
if ( found > 0 ) {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    47
	print( "\n" + found + " Error(s) found.\n" );
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    48
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    49
} else {
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    50
	print( "JSLint check passed.\n" );
62612c69699f added jslint to the build.
hamidouk
parents:
diff changeset
    51
}