jslint 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  http://www.JSON.org/json2.js
3
- 2010-08-25
3
+ 2011-02-23
4
4
 
5
5
  Public Domain.
6
6
 
@@ -141,7 +141,7 @@
141
141
  redistribute.
142
142
  */
143
143
 
144
- /*jslint evil: true, strict: false */
144
+ /*jslint evil: true, strict: false, regexp: false */
145
145
 
146
146
  /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
147
147
  call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
@@ -153,11 +153,13 @@
153
153
  // Create a JSON object only if one does not already exist. We create the
154
154
  // methods in a closure to avoid creating global variables.
155
155
 
156
- if (!this.JSON) {
157
- this.JSON = {};
156
+ var JSON;
157
+ if (!JSON) {
158
+ JSON = {};
158
159
  }
159
160
 
160
161
  (function () {
162
+ "use strict";
161
163
 
162
164
  function f(n) {
163
165
  // Format integers to have at least two digits.
@@ -169,19 +171,19 @@ if (!this.JSON) {
169
171
  Date.prototype.toJSON = function (key) {
170
172
 
171
173
  return isFinite(this.valueOf()) ?
172
- this.getUTCFullYear() + '-' +
173
- f(this.getUTCMonth() + 1) + '-' +
174
- f(this.getUTCDate()) + 'T' +
175
- f(this.getUTCHours()) + ':' +
176
- f(this.getUTCMinutes()) + ':' +
177
- f(this.getUTCSeconds()) + 'Z' : null;
174
+ this.getUTCFullYear() + '-' +
175
+ f(this.getUTCMonth() + 1) + '-' +
176
+ f(this.getUTCDate()) + 'T' +
177
+ f(this.getUTCHours()) + ':' +
178
+ f(this.getUTCMinutes()) + ':' +
179
+ f(this.getUTCSeconds()) + 'Z' : null;
178
180
  };
179
181
 
180
- String.prototype.toJSON =
181
- Number.prototype.toJSON =
182
- Boolean.prototype.toJSON = function (key) {
183
- return this.valueOf();
184
- };
182
+ String.prototype.toJSON =
183
+ Number.prototype.toJSON =
184
+ Boolean.prototype.toJSON = function (key) {
185
+ return this.valueOf();
186
+ };
185
187
  }
186
188
 
187
189
  var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
@@ -207,13 +209,11 @@ if (!this.JSON) {
207
209
  // sequences.
208
210
 
209
211
  escapable.lastIndex = 0;
210
- return escapable.test(string) ?
211
- '"' + string.replace(escapable, function (a) {
212
- var c = meta[a];
213
- return typeof c === 'string' ? c :
214
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
215
- }) + '"' :
216
- '"' + string + '"';
212
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
213
+ var c = meta[a];
214
+ return typeof c === 'string' ? c :
215
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
216
+ }) + '"' : '"' + string + '"';
217
217
  }
218
218
 
219
219
  function str(key, holder) {
@@ -295,11 +295,9 @@ if (!this.JSON) {
295
295
  // Join all of the elements together, separated with commas, and wrap them in
296
296
  // brackets.
297
297
 
298
- v = partial.length === 0 ? '[]' :
299
- gap ? '[\n' + gap +
300
- partial.join(',\n' + gap) + '\n' +
301
- mind + ']' :
302
- '[' + partial.join(',') + ']';
298
+ v = partial.length === 0 ? '[]' : gap ?
299
+ '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
300
+ '[' + partial.join(',') + ']';
303
301
  gap = mind;
304
302
  return v;
305
303
  }
@@ -309,8 +307,8 @@ if (!this.JSON) {
309
307
  if (rep && typeof rep === 'object') {
310
308
  length = rep.length;
311
309
  for (i = 0; i < length; i += 1) {
312
- k = rep[i];
313
- if (typeof k === 'string') {
310
+ if (typeof rep[i] === 'string') {
311
+ k = rep[i];
314
312
  v = str(k, value);
315
313
  if (v) {
316
314
  partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -322,7 +320,7 @@ if (!this.JSON) {
322
320
  // Otherwise, iterate through all of the keys in the object.
323
321
 
324
322
  for (k in value) {
325
- if (Object.hasOwnProperty.call(value, k)) {
323
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
326
324
  v = str(k, value);
327
325
  if (v) {
328
326
  partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -334,9 +332,9 @@ if (!this.JSON) {
334
332
  // Join all of the member texts together, separated with commas,
335
333
  // and wrap them in braces.
336
334
 
337
- v = partial.length === 0 ? '{}' :
338
- gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
339
- mind + '}' : '{' + partial.join(',') + '}';
335
+ v = partial.length === 0 ? '{}' : gap ?
336
+ '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
337
+ '{' + partial.join(',') + '}';
340
338
  gap = mind;
341
339
  return v;
342
340
  }
@@ -377,7 +375,7 @@ if (!this.JSON) {
377
375
  rep = replacer;
378
376
  if (replacer && typeof replacer !== 'function' &&
379
377
  (typeof replacer !== 'object' ||
380
- typeof replacer.length !== 'number')) {
378
+ typeof replacer.length !== 'number')) {
381
379
  throw new Error('JSON.stringify');
382
380
  }
383
381
 
@@ -406,7 +404,7 @@ if (!this.JSON) {
406
404
  var k, v, value = holder[key];
407
405
  if (value && typeof value === 'object') {
408
406
  for (k in value) {
409
- if (Object.hasOwnProperty.call(value, k)) {
407
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
410
408
  v = walk(value, k);
411
409
  if (v !== undefined) {
412
410
  value[k] = v;
@@ -446,9 +444,9 @@ if (!this.JSON) {
446
444
  // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
447
445
 
448
446
  if (/^[\],:{}\s]*$/
449
- .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
450
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
451
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
447
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
448
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
449
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
452
450
 
453
451
  // In the third stage we use the eval function to compile the text into a
454
452
  // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
@@ -0,0 +1,69 @@
1
+ ###
2
+ (c) 2010 Geraud Boyer
3
+ Adapted from rhino.js from Douglas Crockford (www.JSLint.com)
4
+
5
+ This is the node companion to fulljslint.js.
6
+ ###
7
+ ###global JSLINT
8
+ ###
9
+ ###jslint rhino: false, node: true, strict: false
10
+ ###
11
+ ###global require,sys,__filename,process
12
+ ###
13
+
14
+ ((args) ->
15
+ sys = require 'sys'
16
+ fs = require 'fs'
17
+ path = require 'path'
18
+
19
+ print_syntax = () ->
20
+ sys.puts 'Usage: jslint.js [options] file.js'
21
+ process.exit 1
22
+
23
+ print_syntax() if args.length is 0
24
+
25
+ filename = path.join path.dirname(__filename), 'jslint.js'
26
+ JSLINT = fs.readFileSync(filename).toString 'UTF8'
27
+ eval JSLINT
28
+
29
+ # Sensible defaults
30
+ options =
31
+ rhino: no, node: no, passfail: no, bitwise: yes, immed: yes, newcap: yes,
32
+ nomen: yes, onevar: yes, plusplus: yes, regexp: yes, undef: yes, white: yes
33
+
34
+ input = null
35
+ input_filename = null
36
+ args.forEach (arg, index) ->
37
+
38
+ if arg.match /^--no-(\w+)$/
39
+ options[RegExp.$1] = no
40
+ else if arg.match /^--(\w+)=(\S.*)$/
41
+ options[RegExp.$1] = JSON.parse(RegExp.$2)
42
+ else if arg.match /^--(\w+)$/
43
+ options[RegExp.$1] = yes
44
+ else
45
+ input_filename = arg
46
+ input = fs.readFileSync input_filename
47
+ if not input
48
+ sys.puts "jslint: Couldn't open file '#{input_filename}'."
49
+ process.exit 1
50
+ else
51
+ # sys.debug('opening input');
52
+ input = input.toString 'UTF8'
53
+ return
54
+
55
+ print_syntax() if not input
56
+
57
+ if not JSLINT input, options
58
+ JSLINT.errors.forEach (error) ->
59
+ if error
60
+ sys.puts "Lint at line #{error.line} character #{error.character}: #{error.reason}"
61
+ sys.puts (error.evidence or '').replace /^\s*(\S*(\s+\S+)*)\s*$/, "$1"
62
+ sys.puts ''
63
+ process.exit 2
64
+ else
65
+ sys.puts "jslint: No problems found in #{input_filename}"
66
+ process.exit 0
67
+
68
+ return
69
+ ) process.ARGV.slice 2
@@ -1,72 +1,77 @@
1
1
  /*
2
- (c) 2010 Geraud Boyer
3
- Adapted from rhino.js from Douglas Crockford (www.JSLint.com)
4
- */
5
- // This is the node companion to fulljslint.js.
6
-
7
- /*global JSLINT */
8
- /*jslint rhino: false, strict: false */
9
- /*global require,sys,__filename,process */
10
-
11
- (function (args) {
12
- var sys = require('sys'),
13
- fs = require('fs'),
14
- path = require('path'),
15
- JSLINT = fs.readFileSync(path.join(path.dirname(__filename), 'fulljslint.js')).toString('UTF8'),
16
- options = {
17
- rhino: true, passfail: false, bitwise: true,
18
- eqeqeq: true, immed: true, newcap: true,
19
- nomen: true, onevar: true, plusplus: true,
20
- regexp: true, undef: true, white: true
21
- },
22
- filename, input;
2
+ (c) 2010 Geraud Boyer
3
+ Adapted from rhino.js from Douglas Crockford (www.JSLint.com)
23
4
 
24
- if (args.length === 0) {
25
- sys.puts('Usage: jslint.js [options] file.js');
5
+ This is the node companion to fulljslint.js.
6
+ */
7
+ /*global JSLINT
8
+ */
9
+ /*jslint rhino: false, node: true, strict: false
10
+ */
11
+ /*global require,sys,__filename,process
12
+ */(function(args) {
13
+ var JSLINT, filename, fs, input, input_filename, options, path, print_syntax, sys;
14
+ sys = require('sys');
15
+ fs = require('fs');
16
+ path = require('path');
17
+ print_syntax = function() {
18
+ sys.puts('Usage: jslint.js [options] file.js');
19
+ return process.exit(1);
20
+ };
21
+ if (args.length === 0) {
22
+ print_syntax();
23
+ }
24
+ filename = path.join(path.dirname(__filename), 'jslint.js');
25
+ JSLINT = fs.readFileSync(filename).toString('UTF8');
26
+ eval(JSLINT);
27
+ options = {
28
+ rhino: false,
29
+ node: false,
30
+ passfail: false,
31
+ bitwise: true,
32
+ immed: true,
33
+ newcap: true,
34
+ nomen: true,
35
+ onevar: true,
36
+ plusplus: true,
37
+ regexp: true,
38
+ undef: true,
39
+ white: true
40
+ };
41
+ input = null;
42
+ input_filename = null;
43
+ args.forEach(function(arg, index) {
44
+ if (arg.match(/^--no-(\w+)$/)) {
45
+ options[RegExp.$1] = false;
46
+ } else if (arg.match(/^--(\w+)=(\S.*)$/)) {
47
+ options[RegExp.$1] = JSON.parse(RegExp.$2);
48
+ } else if (arg.match(/^--(\w+)$/)) {
49
+ options[RegExp.$1] = true;
50
+ } else {
51
+ input_filename = arg;
52
+ input = fs.readFileSync(input_filename);
53
+ if (!input) {
54
+ sys.puts("jslint: Couldn't open file '" + input_filename + "'.");
26
55
  process.exit(1);
56
+ } else {
57
+ input = input.toString('UTF8');
58
+ }
27
59
  }
28
- eval(JSLINT);
29
-
30
- args.forEach(function (arg, index) {
31
- // sys.debug("Arg(" + index + "): " + arg);
32
- if (arg.match(/^--no-(\w+)$/)) {
33
- // sys.debug("a=false");
34
- options[RegExp.$1] = false;
35
- }
36
- else if (arg.match(/^--(\w+)=(\S.*)$/)) {
37
- // sys.debug("a=b");
38
- // sys.debug("value: " + RegExp.$2);
39
- options[RegExp.$1] = JSON.parse(RegExp.$2);
40
- }
41
- else if (arg.match(/^--(\w+)$/)) {
42
- // sys.debug("a=true");
43
- options[RegExp.$1] = true;
44
- }
45
- else {
46
- filename = arg;
47
- input = fs.readFileSync(filename);
48
- if (!input) {
49
- sys.puts("jslint: Couldn't open file '" + filename + "'.");
50
- process.exit(1);
51
- }
52
- else {
53
- // sys.debug('opening input');
54
- input = input.toString('UTF8');
55
- }
56
- }
60
+ });
61
+ if (!input) {
62
+ print_syntax();
63
+ }
64
+ if (!JSLINT(input, options)) {
65
+ JSLINT.errors.forEach(function(error) {
66
+ if (error) {
67
+ sys.puts("Lint at line " + error.line + " character " + error.character + ": " + error.reason);
68
+ sys.puts((error.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
69
+ return sys.puts('');
70
+ }
57
71
  });
58
- if (!JSLINT(input, options)) {
59
- JSLINT.errors.forEach(function (error) {
60
- if (error) {
61
- sys.puts('Lint at line ' + error.line + ' character ' + error.character + ': ' + error.reason);
62
- sys.puts((error.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
63
- sys.puts('');
64
- }
65
- });
66
- process.exit(2);
67
- }
68
- else {
69
- sys.puts("jslint: No problems found in " + filename);
70
- process.exit(0);
71
- }
72
- }(process.ARGV.slice(2)));
72
+ process.exit(2);
73
+ } else {
74
+ sys.puts("jslint: No problems found in " + input_filename);
75
+ process.exit(0);
76
+ }
77
+ })(process.ARGV.slice(2));
@@ -0,0 +1,59 @@
1
+ ###
2
+ rhino.js
3
+ 2009-09-11
4
+ Copyright (c) 2002 Douglas Crockford (www.JSLint.com) Rhino Edition
5
+
6
+ Converted to CoffeeScript by Geraud Boyer
7
+
8
+ This is the Rhino companion to fulljslint.js.
9
+
10
+ ###
11
+
12
+ ###global JSLINT
13
+ ###
14
+ ###jslint rhino: true, strict: false
15
+ ###
16
+ #
17
+ do (arguments) ->
18
+
19
+ print_syntax = () ->
20
+ sys.puts 'Usage: jslint.js [options] file.js'
21
+ quit 1
22
+
23
+ print_syntax() if not arguments[0]
24
+
25
+ options =
26
+ rhino: no, node: no, passfail: no, strict: no, bitwise: yes, newcap: yes,
27
+ nomen: yes, onevar: yes, plusplus: yes, regexp: yes, undef: yes, white: yes
28
+
29
+ input = null
30
+ input_filename = null
31
+
32
+ for arg in arguments
33
+ do (arg)->
34
+ if arg.match /^--no-(\w+)$/
35
+ options[RegExp.$1] = no
36
+ else if arg.match /^--(\w+)=(\S.*)$/
37
+ options[RegExp.$1] = JSON.parse RegExp.$2
38
+ else if arg.match /^--(\w+)$/
39
+ options[RegExp.$1] = yes
40
+ else
41
+ input_filename = arg
42
+ input = readFile input_filename
43
+ if not input
44
+ print "jslint: Couldn't open file '#{input_filename}'."
45
+ quit 1
46
+ return
47
+
48
+ print_syntax() if not input
49
+
50
+ if not JSLINT input, options
51
+ JSLINT.errors.forEach (error) ->
52
+ if error
53
+ print "Lint at line #{error.line} character #{error.character}: #{error.reason}"
54
+ print (error.evidence or '').replace /^\s*(\S*(\s+\S+)*)\s*$/, "$1"
55
+ print ''
56
+ quit 2
57
+ else
58
+ print "jslint: No problems found in #{input_filename}"
59
+ quit 0
@@ -1,59 +1,75 @@
1
- // rhino.js
2
- // 2009-09-11
3
1
  /*
4
- Copyright (c) 2002 Douglas Crockford (www.JSLint.com) Rhino Edition
5
- */
2
+ rhino.js
3
+ 2009-09-11
4
+ Copyright (c) 2002 Douglas Crockford (www.JSLint.com) Rhino Edition
6
5
 
7
- // This is the Rhino companion to fulljslint.js.
6
+ Converted to CoffeeScript by Geraud Boyer
8
7
 
9
- /*global JSLINT */
10
- /*jslint rhino: true, strict: false */
8
+ This is the Rhino companion to fulljslint.js.
11
9
 
12
- (function (a) {
13
- var e, i, options, arg;
14
- if (!a[0]) {
15
- print("Usage: jslint.js [options] file.js");
16
- quit(1);
17
- }
18
- options = {
19
- rhino: true, passfail:false,
20
- bitwise: true, eqeqeq: true, immed: true,
21
- newcap: true, nomen: true, onevar: true, plusplus: true,
22
- regexp: true, undef: true, white: true
23
- };
24
- while((arg = a.shift())) {
25
- if (arg.match(/^--no(\w+)$/)) {
26
- options[RegExp.$1] = false;
27
- }
28
- else if (arg.match(/^--(\w+)=(\S.*)$/)) {
29
- options[RegExp.$1] = JSON.parse(RegExp.$2);
30
- }
31
- else if (arg.match(/^--(\w+)$/)) {
32
- options[RegExp.$1] = true;
33
- }
34
- else {
35
- var filename = arg
36
- var input = readFile(filename);
37
- if (!input) {
38
- print("jslint: Couldn't open file '" + filename + "'.");
39
- quit(1);
40
- }
41
- }
42
- }
43
- if (!JSLINT(input, options)) {
44
- for (i = 0; i < JSLINT.errors.length; i += 1) {
45
- e = JSLINT.errors[i];
46
- if (e) {
47
- print('Lint at line ' + e.line + ' character ' +
48
- e.character + ': ' + e.reason);
49
- print((e.evidence || '').
50
- replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
51
- print('');
52
- }
53
- }
54
- quit(2);
10
+ */
11
+ /*global JSLINT
12
+ */
13
+ /*jslint rhino: true, strict: false
14
+ */(function(arguments) {
15
+ var arg, input, input_filename, options, print_syntax, _fn, _i, _len;
16
+ print_syntax = function() {
17
+ sys.puts('Usage: jslint.js [options] file.js');
18
+ return quit(1);
19
+ };
20
+ if (!arguments[0]) {
21
+ print_syntax();
22
+ }
23
+ options = {
24
+ rhino: false,
25
+ node: false,
26
+ passfail: false,
27
+ strict: false,
28
+ bitwise: true,
29
+ newcap: true,
30
+ nomen: true,
31
+ onevar: true,
32
+ plusplus: true,
33
+ regexp: true,
34
+ undef: true,
35
+ white: true
36
+ };
37
+ input = null;
38
+ input_filename = null;
39
+ _fn = function(arg) {
40
+ if (arg.match(/^--no-(\w+)$/)) {
41
+ options[RegExp.$1] = false;
42
+ } else if (arg.match(/^--(\w+)=(\S.*)$/)) {
43
+ options[RegExp.$1] = JSON.parse(RegExp.$2);
44
+ } else if (arg.match(/^--(\w+)$/)) {
45
+ options[RegExp.$1] = true;
55
46
  } else {
56
- print("jslint: No problems found in " + a[0]);
57
- quit();
47
+ input_filename = arg;
48
+ input = readFile(input_filename);
49
+ if (!input) {
50
+ print("jslint: Couldn't open file '" + input_filename + "'.");
51
+ quit(1);
52
+ }
58
53
  }
59
- }(arguments));
54
+ };
55
+ for (_i = 0, _len = arguments.length; _i < _len; _i++) {
56
+ arg = arguments[_i];
57
+ _fn(arg);
58
+ }
59
+ if (!input) {
60
+ print_syntax();
61
+ }
62
+ if (!JSLINT(input, options)) {
63
+ JSLINT.errors.forEach(function(error) {
64
+ if (error) {
65
+ print("Lint at line " + error.line + " character " + error.character + ": " + error.reason);
66
+ print((error.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
67
+ return print('');
68
+ }
69
+ });
70
+ return quit(2);
71
+ } else {
72
+ print("jslint: No problems found in " + input_filename);
73
+ return quit(0);
74
+ }
75
+ })(arguments);