Merge branch 'i382' of https://github.com/kberg/dygraphs into i382
[dygraphs.git] / jshint / env / jsc.js
1 /*jshint boss:true, evil:true */
2
3 // usage:
4 // jsc ${env_home}/jsc.js -- ${file} "$(cat ${file})" "{option1:true,option2:false} ${env_home}"
5 var env_home = '';
6 if (arguments.length > 3) {
7 env_home = arguments[3].toString().replace(/\/env$/, '/');
8 }
9 load(env_home + "jshint.js");
10
11 if (typeof(JSHINT) === 'undefined') {
12 print('jshint: Could not load jshint.js, tried "' + env_home + 'jshint.js".');
13 quit();
14 }
15
16 (function(args){
17 var home = args[3],
18 name = args[0],
19 input = args[1],
20 opts = (function(arg){
21 var opts = {};
22 var item;
23
24 switch (arg) {
25 case undefined:
26 case '':
27 return opts;
28 default:
29 arg = arg.split(',');
30 for (var i = 0, ii = arg.length; i < ii; i++) {
31 item = arg[i].split(':');
32 opts[item[0]] = eval(item[1]);
33 }
34 return opts;
35 }
36 })(args[2]);
37
38 if (!name) {
39 print('jshint: No file name was provided.');
40 quit();
41 }
42
43 if (!input) {
44 print('jshint: ' + name + ' contents were not provided to jshint.');
45 quit();
46 }
47
48 if (!JSHINT(input, opts)) {
49 for (var i = 0, err; err = JSHINT.errors[i]; i++) {
50 print(err.reason + ' (line: ' + err.line + ', character: ' + err.character + ')');
51 print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
52 print('');
53 }
54 }
55
56 var data = JSHINT.data();
57 if (data.unused !== undefined) {
58 for (var i = 0, unused; unused = data.unused[i]; i++) {
59 print('Unused variable "' + unused.name + '" (line: ' + unused.line + ')');
60 }
61 }
62
63 // if (data.globals !== undefined) {
64 // for (var i = 0, globals; global = data.globals[i]; i++) {
65 // print('Global variable "' + global + '"');
66 // }
67 // }
68
69 if (data.implieds !== undefined) {
70 for (var i = 0, implied; implied = data.implieds[i]; i++) {
71 print('Implied global variable "' + implied.name + '" (line: ' + implied.line + ')');
72 }
73 }
74
75 // print('Errors: ' + JSHINT.errors.length);
76 // print(JSHINT.report(true));
77
78 quit();
79 })(arguments);