JSLint in Vim through Lynx

2008-09-07 00:50:00

I recently saw a nice blog post by Mike Cantelon on integrating JSLint with Vim, and since I spend most of my days hacking JavaScript in Vim, it was a no-brainer for me to want that integrated-JSLint awesomeness, and right now, dammit.

Of course I already had SpiderMonkey (sudo apt-get install spidermonkey-bin for you Ubuntu/Debian types), and quickly downloaded the needed fulljslint.js file. (I stuck it in /usr/lib.)

However, once I started going through the steps to set it up, a couple of improvements occurred to me.

First of all, when I got to the point of calling JSLint from SpiderMonkey (a la Ian Bicking's post, I saved myself a step of indirection by making the script an actual executable, rather than passing it to the js executable. I just added the usual shebang) line, and the path to the js executable at the top.

Here's my whole runjslint script, that I stuck in /usr/bin:


var body = arguments[0];

var result = JSLINT(body, {
  browser: true,
  forin: true
if (result) {
 print('How are you gentlemen. :)');
} else {
 print('Somebody set up us the bomb! :/');

Next, being a JavaScript guy, the idea of using a Python script to format the JSLint HTML output into plaintext seemed somehow less-than-satisfying.

I actually started to add a quick inline formatting step directly in the js command-line script, but I quickly realized that the JSLint output had a pretty complicated structure, and simple splitting/removing-tags just wasn't going to cut it for me anyhow. I wanted something a little nicer.

Using Lynx (sudo apt-get install lynx) seemed to me an obvious approach -- and as it turns out, at least under Linux it's easy to use Lynx as a filter to convert HTML output to plaintext in a shell command. (I'm not sure how you'd do it under OSX or one of the other BSDish OS's, but I'd assume there's a way to make it work.)

Here's what I added to my .exrc, including the piping through lynx, to create the filter:

cabbr jslint !runjslint "<code>cat %" \ \| lynx --force-html /dev/fd/5 -dump 5<&0 \| less

It was really cool to see how easily this could be done, and with these small improvements, it's even nicer.

I find myself JSLinting now pretty regularly throughout the day -- especially once I got JSLint to shut up about one-shot constructor functions for namespace objects. And I guess that's a pretty specific tweak that might be worth another post.


This post seems to have attracted some linkage, as evinced by the large number of apparently manually-added spam comments I've just had to remove.

The text is not machine-generated, and purports to respond to something actually in the post, but the link for the author is a spam link.

Comments for this article are now closed. If you have something relevant, do please send it to me via e-mail and I'll keep this updated.


Via e-mail (comments are closed due to spammer asshats) -- from Andy Walker, a hacked-up Rhino-based JSLint which can accept input from a pipe or as a redirect target:



This is the blog for Matthew Eernisse. I currently work at Yammer as a developer, working mostly with JavaScript. All opinions expressed here are my own, not my employer's.


Previous posts

All previous posts ยป

This blog is a GeddyJS application.