jslintrb 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ {"gettersetter": true}
@@ -1,3 +1,7 @@
1
+ === 0.6.0 / 2010-03-30
2
+
3
+ * add Nick Galbreath's idea of mangling getter/setter syntax to get through the non-ES5 parser
4
+
1
5
  === 0.5.0 / 2010-03-17
2
6
 
3
7
  * Cleanup wake integration; add opt to avoid new upstream error
@@ -1,8 +1,10 @@
1
+ .jslintrbrc
1
2
  CHANGELOG.rdoc
2
3
  LICENSE
3
4
  Manifest.txt
4
5
  README.rdoc
5
6
  Rakefile
7
+ Wakefile
6
8
  bin/jslintrb
7
9
  lib/jslintrb.rb
8
10
  lib/jslintrb/fulljslint.js
@@ -29,6 +29,13 @@ example at http://github.com/smparkes/env-js/blob/envjsrb/.jslintrbrc.
29
29
 
30
30
  JSLint warns against using new to be evaluated soley for side-effects. jslintrb allows this if you set the "newside" option.
31
31
 
32
+ Upstream doesn't support ECMAScript 5 getters and setters. Nick
33
+ Galbreath (http://blog.client9.com/) had the idea of just using a
34
+ regexp to mangle the common cases for the purposes of jslint until
35
+ upstream suports them. You can do this now in jslintrb by setting the
36
+ "gettersetter" option to true. Note that this option has to be turned
37
+ on in a .jslintrbrc file; it can't be turned on with inline comments.
38
+
32
39
  == Copyright
33
40
 
34
41
  jslintrb copyright (c) 2010 Steven Parkes. See LICENSE for details.
@@ -0,0 +1,3 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ jslintrb "lib/**/*"
@@ -1,3 +1,3 @@
1
1
  module JSLintRB
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -247,6 +247,7 @@ SOFTWARE.
247
247
  "white-space", whitesmoke, widget, width, "word-spacing", "word-wrap",
248
248
  yahooCheckLogin, yahooLogin, yahooLogout, yellow, yellowgreen,
249
249
  "z-index"
250
+ , "newside"
250
251
  */
251
252
 
252
253
 
@@ -1,7 +1,7 @@
1
1
  /*global Ruby, JSLINT */
2
2
  /*jslint
3
3
  evil: true, nomen: false, onevar: false, regexp: false, strict: true, indent: 2
4
- plusplus: false
4
+ plusplus: false, white: false, gettersetter: true
5
5
  */
6
6
 
7
7
  "use strict";
@@ -25,64 +25,98 @@
25
25
 
26
26
  var errors = 0;
27
27
 
28
+ var gettersetter_error = function(file, line_number, reason, line) {
29
+ Ruby.print(file + ' line ' + line_number + ' character 0: ' + reason + '\n');
30
+ Ruby.print(line+"\n");
31
+ Ruby.send("eval", "$stdout.flush");
32
+ Ruby.send("eval", "$stderr.flush");
33
+ };
34
+
28
35
  var files = Ruby.send("eval", "ENV['JSLINT_FILES']");
29
36
  files = files.split(":");
30
37
  for (var i = 0; i < files.length; i++) {
31
38
  var file = files[i];
32
39
 
33
40
  var batches = [];
34
- batches.push( default_options );
41
+ batches.push(default_options);
35
42
 
36
43
  var dirs = file.split("/");
37
44
 
38
45
  var list = [ ".jslintrbrc" ];
39
- var d;
40
- for(var d=1; d < dirs.length; d++){
41
- list.push(dirs.slice(0,d).join("/")+"/.jslintrbrc");
46
+ for (var d = 1; d < dirs.length; d++) {
47
+ list.push(dirs.slice(0, d).join("/") + "/.jslintrbrc");
42
48
  }
43
49
 
44
50
  var rc;
45
- for(d=0; d<list.length; d++){
51
+ for (d = 0; d < list.length; d++) {
46
52
  var opts;
47
53
  try {
48
54
  opts = Ruby.IO.read(list[d]);
49
- } catch (ex) {
55
+ } catch (ex0) {
50
56
  opts = undefined;
51
57
  }
52
58
 
53
59
  if (opts) {
54
60
  try {
55
61
  opts = JSON.parse(opts);
62
+
56
63
  batches.push(opts);
57
- } catch(e) {
58
- throw new Error("could not parse "+list[d]+" as JSON");
64
+ } catch (ex1) {
65
+ throw new Error("could not parse " + list[d] + " as JSON");
59
66
  }
60
67
  }
61
68
  }
62
69
  var options = {};
63
70
  var b;
64
- for (b=0; b<batches.length; b++) {
71
+ for (b = 0; b < batches.length; b++) {
65
72
  var key;
66
- for(key in batches[b]) {
73
+ for (key in batches[b]) {
67
74
  options[key] = batches[b][key];
68
75
  }
69
76
  }
70
77
 
71
78
  var contents = Ruby.IO.read(file);
79
+ var regex = /(.*)\s+(get|set)\s+(\w+)\s*\(([^)]*)\)(.*)/;
80
+ var se = Ruby.send("eval", "$stderr");
81
+
82
+ if (options.gettersetter) {
83
+ contents = contents.split("\n");
84
+ for (var l = 0; l < contents.length; l++ ) {
85
+ var line = contents[l];
86
+ var match = line.match(regex);
87
+ if (match) {
88
+ if (match[2] === "get") {
89
+ if ( !match[4].match(/^\s*$/) ) {
90
+ gettersetter_error(file, l, "getter has an argument: "+match[4], line);
91
+ }
92
+ } else if (match[2] === "set") {
93
+ if ( match[4].match(/^\s*$/) ) {
94
+ gettersetter_error(file, l, "setter has no argument");
95
+ }
96
+ if ( match[4].match(/,/) ) {
97
+ gettersetter_error(file, l, "setter has multiple arguments: "+match[4]);
98
+ }
99
+ }
100
+ contents[l] = [ match[1], match[2], "_", match[3], ": function (", match[4], ")", match[5] ].join("");
101
+
102
+ }
103
+ }
104
+ contents = contents.join("\n");
105
+ }
106
+
72
107
  var success = JSLINT(contents, options);
73
108
  if (success) {
74
109
  } else {
75
110
  errors += JSLINT.errors.length;
76
- for (j = 0; j < JSLINT.errors.length; j += 1) {
111
+ for (var j = 0; j < JSLINT.errors.length; j += 1) {
77
112
  var e = JSLINT.errors[j];
78
113
  if (e) {
79
-
80
114
  Ruby.print(file + ' line ' + e.line + ' character ' +
81
115
  e.character + ': ' + e.reason + '\n');
82
116
  Ruby.print((e.evidence || '').
83
117
  replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") + '\n');
84
- Ruby.send("eval","$stdout.flush");
85
- Ruby.send("eval","$stderr.flush");
118
+ Ruby.send("eval", "$stdout.flush");
119
+ Ruby.send("eval", "$stderr.flush");
86
120
  }
87
121
  }
88
122
  }
@@ -93,3 +127,24 @@
93
127
  }
94
128
 
95
129
  }());
130
+
131
+ /* What the heck, a test getter/setter: self testing code? */
132
+ var x = {
133
+ get a() {
134
+ return 10;
135
+ },
136
+ /*
137
+ g_et b(x) {
138
+ return 10;
139
+ },
140
+ s_et d(y, z) {
141
+ return 10;
142
+ },
143
+ s_et e() {
144
+ return 10;
145
+ },
146
+ */
147
+ set c(y) {
148
+ return 10;
149
+ }
150
+ };
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
7
+ - 6
8
8
  - 0
9
- version: 0.5.0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Steven Parkes
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 -07:00
17
+ date: 2010-03-30 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -73,11 +73,13 @@ extensions: []
73
73
  extra_rdoc_files:
74
74
  - Manifest.txt
75
75
  files:
76
+ - .jslintrbrc
76
77
  - CHANGELOG.rdoc
77
78
  - LICENSE
78
79
  - Manifest.txt
79
80
  - README.rdoc
80
81
  - Rakefile
82
+ - Wakefile
81
83
  - bin/jslintrb
82
84
  - lib/jslintrb.rb
83
85
  - lib/jslintrb/fulljslint.js