Integrating JavaScriptLint With Vim On Windows
- November 5th, 2009
- Posted in JavaScript . Vim
- Write comment
I use Vim to code JavaScript on my work machine, a PC running WinXp. Looking around for a way to integrate a good lint program to catch typical .js errors I found JavaScriptLint.vim. The instructions there are simple, drop the script in your vim/plugins folder after the jsl.exe program has been installed. That executable, the javascriptlint program itself, has good documentation for Vim integration on Linux (which works well btw) but none for Windows. Here is what I did:
- First, download the version for windows here
- Extract that .zip anywhere, doesn’t matter
- From the extracted folder grab the jsl.exe and jsl.default.conf files and put them in your C:\Program Files\Vim\Vim72 folder (If you’re using Vim 7.2, I would assume other versions have a similar folder structure. It’s the same directory the gvim.exe, vim.exe and others are in).
- Drop the JavaScriptLint.vim file in C:\Program Files\Vim\vim72\plugin
Now, you’re almost done. Open up the jsl.default.conf file in a text editor and in the ‘Defining Identifiers’ section enable ‘always_use_option_explicit’ like so:
# By default, "option explicit" is enabled on a per-file basis.
# To enable this for all files, use "+always_use_option_explicit"
+always_use_option_explicit
Also, just below the ‘common uses for webpages might be: line I added these, a la Ken Guest:
+define ActiveXObject
+define addEventListener
+define alert
+define attributes
+define blur
+define childNodes
+define click
+define clearTimeout
+define dispatchEvent
+define document
+define firstChild
+define focus
+define Image
+define item
+define lastChild
+define localName
+define namespaceURI
+define navigator
+define nextSibling
+define nodeName
+define nodeType
+define nodeValue
+define ownerDocument
+define parent
+define parentNode
+define prefix
+define previousSibling
+define removeEventListener
+define screen
+define scrollIntoView
+define setTimeout
+define tagName
+define window
+define XMLHttpRequest
The last thing I did, and this just because it looked like the correct thing to do, was I commented out the ‘files’ section test file since Vim is sending the file for me (and since I didn’t drop that file in from the extracted folder anyway…):
# Specify which files to lint
# Use "+recurse" to enable recursion (disabled by default).
# To add a set of files, use "+process FileName", "+process Folder\Path\*.js",
# or "+process Folder\Path\*.htm".
#
#+process jsl-test.js
Now, Action! Let’s say I just hacked together this object literal (which, I just did…) and saved it, seems OK, no errors reported:

Not triggering the .js lint error messages
Now, what if I had forgot to put a semicolon after the loadMap() function call in the objects init: and then saved?

Error warning triggered
The ‘quickfix’ window opens with the error highlighted. The line number here seems to be incorrect as line 23 is where the closing brace is, the actual missing semicolon should be on line 21. This is, however, the first run and may be a matter of configuration. Still a great start I think


No comments yet.