Skip to content
Browse files

add Nick Galbreath's idea of mangling getter/setter syntax to get thr…

…ough the non-ES5 parser
  • Loading branch information...
1 parent 92ac0d3 commit 7e7265b60d232631f10d1ca5b6710fc01e33cead @smparkes committed Mar 30, 2010
Showing with 85 additions and 39 deletions.
  1. +2 −23 .gitignore
  2. +1 −0 .jslintrbrc
  3. +7 −0 README.rdoc
  4. +3 −0 Wakefile
  5. +1 −1 lib/jslintrb.rb
  6. +1 −0 lib/jslintrb/fulljslint.js
  7. +70 −15 lib/jslintrb/jslintrb.js
View
25 .gitignore
@@ -1,23 +1,2 @@
-## MAC OS
-.DS_Store
-
-## TEXTMATE
-*.tmproj
-tmtags
-
-## EMACS
-*~
-\#*
-.\#*
-
-## VIM
-*.swp
-
-## PROJECT::GENERAL
-coverage
-rdoc
-pkg
-
-## PROJECT::SPECIFIC
-
-/jslintrb.gemspec
+/pkg
+/.wake
View
1 .jslintrbrc
@@ -0,0 +1 @@
+{"gettersetter": true}
View
7 README.rdoc
@@ -29,6 +29,13 @@ example at http://github.com/smparkes/env-js/blob/envjsrb/.jslintrbrc.
JSLint warns against using new to be evaluated soley for side-effects. jslintrb allows this if you set the "newside" option.
+Upstream doesn't support ECMAScript 5 getters and setters. Nick
+Galbreath (http://blog.client9.com/) had the idea of just using a
+regexp to mangle the common cases for the purposes of jslint until
+upstream suports them. You can do this now in jslintrb by setting the
+"gettersetter" option to true. Note that this option has to be turned
+on in a .jslintrbrc file; it can't be turned on with inline comments.
+
== Copyright
jslintrb copyright (c) 2010 Steven Parkes. See LICENSE for details.
View
3 Wakefile
@@ -0,0 +1,3 @@
+# -*- mode: ruby -*-
+
+jslintrb "lib/**/*"
View
2 lib/jslintrb.rb
@@ -1,3 +1,3 @@
module JSLintRB
- VERSION = "0.5.0"
+ VERSION = "0.6.0"
end
View
1 lib/jslintrb/fulljslint.js
@@ -247,6 +247,7 @@ SOFTWARE.
"white-space", whitesmoke, widget, width, "word-spacing", "word-wrap",
yahooCheckLogin, yahooLogin, yahooLogout, yellow, yellowgreen,
"z-index"
+ , "newside"
*/
View
85 lib/jslintrb/jslintrb.js
@@ -1,7 +1,7 @@
/*global Ruby, JSLINT */
/*jslint
evil: true, nomen: false, onevar: false, regexp: false, strict: true, indent: 2
- plusplus: false
+ plusplus: false, white: false, gettersetter: true
*/
"use strict";
@@ -25,64 +25,98 @@
var errors = 0;
+ var gettersetter_error = function(file, line_number, reason, line) {
+ Ruby.print(file + ' line ' + line_number + ' character 0: ' + reason + '\n');
+ Ruby.print(line+"\n");
+ Ruby.send("eval", "$stdout.flush");
+ Ruby.send("eval", "$stderr.flush");
+ };
+
var files = Ruby.send("eval", "ENV['JSLINT_FILES']");
files = files.split(":");
for (var i = 0; i < files.length; i++) {
var file = files[i];
var batches = [];
- batches.push( default_options );
+ batches.push(default_options);
var dirs = file.split("/");
var list = [ ".jslintrbrc" ];
- var d;
- for(var d=1; d < dirs.length; d++){
- list.push(dirs.slice(0,d).join("/")+"/.jslintrbrc");
+ for (var d = 1; d < dirs.length; d++) {
+ list.push(dirs.slice(0, d).join("/") + "/.jslintrbrc");
}
var rc;
- for(d=0; d<list.length; d++){
+ for (d = 0; d < list.length; d++) {
var opts;
try {
opts = Ruby.IO.read(list[d]);
- } catch (ex) {
+ } catch (ex0) {
opts = undefined;
}
if (opts) {
try {
opts = JSON.parse(opts);
+
batches.push(opts);
- } catch(e) {
- throw new Error("could not parse "+list[d]+" as JSON");
+ } catch (ex1) {
+ throw new Error("could not parse " + list[d] + " as JSON");
}
}
}
var options = {};
var b;
- for (b=0; b<batches.length; b++) {
+ for (b = 0; b < batches.length; b++) {
var key;
- for(key in batches[b]) {
+ for (key in batches[b]) {
options[key] = batches[b][key];
}
}
var contents = Ruby.IO.read(file);
+ var regex = /(.*)\s+(get|set)\s+(\w+)\s*\(([^)]*)\)(.*)/;
+ var se = Ruby.send("eval", "$stderr");
+
+ if (options.gettersetter) {
+ contents = contents.split("\n");
+ for (var l = 0; l < contents.length; l++ ) {
+ var line = contents[l];
+ var match = line.match(regex);
+ if (match) {
+ if (match[2] === "get") {
+ if ( !match[4].match(/^\s*$/) ) {
+ gettersetter_error(file, l, "getter has an argument: "+match[4], line);
+ }
+ } else if (match[2] === "set") {
+ if ( match[4].match(/^\s*$/) ) {
+ gettersetter_error(file, l, "setter has no argument");
+ }
+ if ( match[4].match(/,/) ) {
+ gettersetter_error(file, l, "setter has multiple arguments: "+match[4]);
+ }
+ }
+ contents[l] = [ match[1], match[2], "_", match[3], ": function (", match[4], ")", match[5] ].join("");
+
+ }
+ }
+ contents = contents.join("\n");
+ }
+
var success = JSLINT(contents, options);
if (success) {
} else {
errors += JSLINT.errors.length;
- for (j = 0; j < JSLINT.errors.length; j += 1) {
+ for (var j = 0; j < JSLINT.errors.length; j += 1) {
var e = JSLINT.errors[j];
if (e) {
-
Ruby.print(file + ' line ' + e.line + ' character ' +
e.character + ': ' + e.reason + '\n');
Ruby.print((e.evidence || '').
replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1") + '\n');
- Ruby.send("eval","$stdout.flush");
- Ruby.send("eval","$stderr.flush");
+ Ruby.send("eval", "$stdout.flush");
+ Ruby.send("eval", "$stderr.flush");
}
}
}
@@ -93,3 +127,24 @@
}
}());
+
+/* What the heck, a test getter/setter: self testing code? */
+var x = {
+ get a() {
+ return 10;
+ },
+/*
+ g_et b(x) {
+ return 10;
+ },
+ s_et d(y, z) {
+ return 10;
+ },
+ s_et e() {
+ return 10;
+ },
+*/
+ set c(y) {
+ return 10;
+ }
+};

0 comments on commit 7e7265b

Please sign in to comment.
Something went wrong with that request. Please try again.