Anton Kovalyov

Interactive JSHint

12 November 2012 — San Francisco

I’m working on refactoring the JSHint source code these days by splitting the main file into independent pieces, improving data structures and so on. And since JSHint was born as a fork of JSLint it has the original author’s signature all over its code. For example, one thing that I’m trying to fix is the fact that we have lots of one- and two- letter variables that can appear anywhere in the file with over 7K lines of code.

Fortunately, JSHint has been invaluable to me since it shows all the spots where I forgot to rename a variable or replace a global function call with a method. Now, I use JSHint strictly from command-line. [1] It works fine except for the part where you get 50+ warnings and then have to either pipe it into your editor or scroll up and down the terminal trying to keep track of all the warnings you have already fixed.

So earlier today I wrote a little JavaScript program that allows me to use JSHint interactively, independent of whatever editor I’m using. I call it jshint-i:

$ npm install jshint-i -g
...
$ jshint-i myfile.js --config=myconfig.json
screenshot

With it, I can easily step through all the warnings generated by JSHint, and be more aware of which ones I’ve fixed (or intentionally skipped). Right now it is pretty basic but I plan to add more stuff to it over time—for example it would be really nice to fix trivial mistakes (like missing semicolons) without going back to the editor, just by invoking another jshint-i command. But that’s a task for another day.

And, of course, keep in mind that jshint-i is not a general purpose tool. This is something I made to help me with my personal workflow. But maybe you’ll find it useful as well.

[1] I know that nowadays most editors have plugins that add JSHint support to them. But I’m not really into plugins, that’s just how I work. (And before you call me crazy let me tell you that I’m also not into syntax highlighting. Now you can call me crazy.)