Run pyflakes/jslint automatically in Vim

As maybe you can tell from the infrequency of updates to this blog, I (and the others with whom I'm working) have been churning out a huge amount of code recently, split roughly evenly between Python and JavaScript. One nice thing I got used to during the month I tried to switch from Vim to TextMate was a plugin that ran pyflakes every time I saved a Python file. After I gave up and went back to Vim, I missed that check. Luckily, other, more vimscript-savvy coders had the same idea. Here's how to set up both pyflakes and jslint to run on save.

  1. pyflakes. I installed this excellent plugin:

    $ git clone git://
    $ mkdir -p ~/.vim/ftplugin/python
    $ cp pyflakes-vim/pyflakes.vim ~/.vim/ftplugin/python
    I also followed his advice and installed his fork of pyflakes, which is incredibly faster than the original version:

    $ git clone git://
    $ cd pyflakes
    $ sudo python install

    This plugin actually highlights errors inline as you edit, and puts details in the status bar when you're over a line with an error:

  2. jslint. This plugin is easier to install, though it doesn't have the same on-the-fly checking as the pyflakes plugin.

    $ git clone git://
    $ cd jslint.vim
    $ rake install

    Then you can run jslint easily from within Vim:


    That'll give you a nice quickfix window with all your extant problems.

    To have it run on save, simply add to ~/.vimrc:

    autocmd BufWritePost *.js JSLint

    Finally, you can also pass options into jslint by putting them in ~/.jslintrc. For example, because I'm working with a few global namespaces/functions defined in other files, I have:

    /* global Ext, Zenoss, _t */

    That way, you can eliminate any noise and get right to the trailing commas.

    I may try my hand at hacking the jslint plugin to do the same inline highlighting as the pyflakes plugin.
Anyway, there it is. Definitely helps keep the silly typos down.


Post a Comment