views:

1298

answers:

5

I'm running JSLint's Rhino version from the Ubuntu command line like so:

$ rhino jslint.js myScript.js

While the web interface offers various options, I couldn't figure out how to invoke those via the command line. Am I overlooking anything in the documentation?

+2  A: 

Yes! You did miss it. You can specify the options for jslint at the top of your .js file. See the doc page and read the options section for an example.

jonstjohn
Thanks!I hadn't even considered to put the options into the .js files themselves...The documentation there says "JSLint accepts an option object" - any way to pass that via the command line?
Not that I know of, unfortunately. You could write a wrapper script to take command-line options and put them at the top of the js file, or create a temporary js file which is just the options + the original. Just an idea, though, never tried it. You could write it an open source it!
jonstjohn
I've had the same thought - shouldn't be hard, but not sure when I'll get around to it.(I'd have to make sure though not to add any line breaks, otherwise the line numbers being reported would be off.)
+1  A: 

I was inspired by the discussion above, and extended my JSLint wrapper script accordingly. It's fairly primitive, but seems to do the job.

This is great, thanks!!
AnC
+2  A: 

My jslint4java project includes a command line tool that allows you to add in flags like --undef. This may be more useful than running it by hand.

Dominic Mitchell
A: 

There is a perl+js wrapper for jslint that Cory Bennet put together (based on Ian Bicking's prior art). It's got command-line options, etc. He even details some Emacs integration via a compile-mode hook.

I had some trouble, and put some notes up on getting it to work in Cygwin and Emacs32.

There are some other options in a similar question: Is there an offline version of jslint for windows?

Michael Paulukonis
That sounds very interesting, thanks!So it's a Perl wrapper that uses Spidermonkey? Sorry FND, but I guess I'll have to abandon your Rhino-based Python script... (I just saw there's a Spidermonkey version as well, but that looks a little unfinished?)
AnC
the Perl-wrapper "just" calls the local javascript interpreter -- I use it with spidermonkey, and there are some instructions for making sure you get the right build of SM, but I don't know if Rhino will work, or not. If you can call it from the command-line, it should work fine (I use it both inside Cygwin, and without).
Michael Paulukonis
more EmacsW32 suggestions @ http://stackoverflow.com/questions/2465821/how-can-i-run-jslint-as-a-javascript-compile-tool-in-emacs-for-windows/2470172
Michael Paulukonis
A: 

I came up with a command line jslint solution based on jQuery's jslint-check.js script, which is executed within Rhino via their Makefile.

Philip Durbin