73rhodes / Sublime-JSLint

JSLint for Sublime Text 2 and 3.
80 stars 14 forks source link

Added support for predefined variables #14

Closed olmaygti closed 10 years ago

olmaygti commented 11 years ago

Hi there Darren,

I installed your jslint plugin yesterday, which I found pretty useful, but wasn't able to find the way to pass some global variables to JSLint.

Inspecting the code, I saw that JSLint accepted predef variables in the form of either an Array or and object (line 6068), so I just made a pretty straigthforward change in linter.js to accept a "predef" argument followed by a string containing a javascript syntax compliant array of strings.

Do as you wish with this commit.

Regards.

darrenderidder commented 11 years ago

The way to declare globals for Jslint is simpler than that:

/global foo, bar/

olmaygti commented 11 years ago

I know, but in my company we use the command line --predef parameter just avoid that: writing those comments with global variables in every single js file on your app, which are just so much.

Or did you mean writing those comments in the JSLint.sublime-build file?? I tried to but I couldn't make it work that way.

darrenderidder commented 11 years ago

If it's supported on the command line, it should be supported in the "advanced build settings", but if it isn't I'll try to add it. Thanks for the heads up!

filiptc commented 10 years ago

Follow-up: it isn't, as far as I've tried. Please add support. Thanks!

may-tau commented 10 years ago

yep, it's still not supported by the plugin and I'd like to have it working too. Here's what I did:

  1. added "predef" value to the argsWithVals array in linter.js
  2. defined my global variable in JSLint.sublime-build cmd array as follows: "--predef", ["my_global_var"]

Trying to Lint after that fails - and does it silently, e.g. console doesn't say anything at all. I presume it's not allowed to use array as value in cmd array of the build file? Because if I use string - the linter runs, but doesn't do anything with my "predef" parameter (which is understandable).

As I don't really want to wait for this to be officially added, I'd like some help on how I get it working. Thanks.

filiptc commented 10 years ago

Just apply 33eff39 (worked for me)

may-tau commented 10 years ago

oh, ok, thanks! But because eval is evil, I changed the array matching in linter.js (24) to:

var array_match = String(val).match(/\[([^\]]+)\]/);
if (array_match) {
  val = array_match[1].replace(/["']/g, '').split(',');
}

would be cool tho, if cmd array could take arrays as values