Skip to content
Advertisement

How to do JSLint in Vim

I spend my days in vim, currently writing a lot of JavaScript. I’ve been trying to find a way to integrate JSLint or something similar into vim to improve my coding. Has anyone managed to do something like this?

I tried this: Javascript Syntax Checking From Vim, unfortunately the output is very crude.

Advertisement

Answer

You can follow the intructions from JSLint web-service + VIM integration or do what I did:

Download http://jslint.webvm.net/mylintrun.js and http://www.jslint.com/fulljslint.js and put them in a directory of your choice.

Then add the following line to the beginning of mylintrun.js:

var filename= arguments[0];

and change last line of code in mylintrun.js (“print( …)”) to:

 print ( filename + ":" + (obj["line"] + 1) + ":" + (obj["character"] + 1) + ":" + obj["reason"] );

This makes in mylintrun.js output a error list that can be used with the VIM quickfix window (:copen).

Now set the following in VIM:

set makeprg=cat % \| /my/path/to/js /my/path/to/mylintrun.js %
set errorformat=%f:%l:%c:%m

where you have to change /my/path/to/js to the path to SpiderMonkey and /my/path/to/mylintrun.js to the path where you put the JS files.

Now, you can use :make in VIM and use the quickfix window (:he quickfix-window) to jump from error to error.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement