betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

02 July 2012

Make Your JavaScript Behave

Installing jsLint into vim

Like most programmers, I'm using JavaScript, because that's the way it is these days. Given the minefield of that language, I really want a tool like jsLint to watch my code behave. So what I did was to integrate jsLint into vim. Which wasn't so difficult at all.

First step Is to get a JavaScript engine. For JavaScript unit tests I already use rhino, but it's a bit slow, especially to start up. The jslint.vim plugin recommends SpiderMonkey, so I gave it a try. There is an OpenBSD port for it, so that was no sweat. It took me a bit of looking up to discover that this will install a JavaScript prompt in /usr/local/bin/js -- neat. The jslint.vim plugin knew that already, so no configuration needed there.

Second step was to install the jslint.vim plugin itself. Here the main necessary hint was to add the command filetype plugin on to my ~/.vimrc file. In ~/.vimrc I also added these lines to be able to switch the highlighting of "complaints" off and on:

" jslint display errors off & on again
map %0 :let g:JSLintHighlightErrorLine = 0<CR>
map %1 :let g:JSLintHighlightErrorLine = 1<CR>

Instead of %1 and %0 you might want to choose some command that suits you better, I'm always at pains finding good command keys in vim that are not used for something else yet.

Now jslint was complaining about too much. The next step is to create a configuration file in ~/.jslintrc to give it some standard settings. Currently for me that's:

/*jslint browser: true, nomen: true, sloppy: true, vars: true, maxerr: 250 */
/*global jQuery, $ */

Any of these settings and any others can be configured on a per-file basis, by adding a comment like that to a JavaScript file.


Posted by betabug at 08:28 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Backyard Adventure (07/08 08:18)
Danakos Climbing Gym (06/26 18:40)
Getting into the Ruby Debugger (06/13 13:36)
The site is coming back (06/11 14:17)
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< In the meantime... | Main | Pastourmas >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/1275/tbping
There are no trackbacks.
Leave a comment