Run pyflakes/jslint automatically in Vim
written by Ian McCracken
at Wednesday, February 3, 2010
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.
- pyflakes. I installed this excellent plugin:
$ git clone git://github.com/kevinw/pyflakes-vim.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://github.com/kevinw/pyflakes.git $ cd pyflakes $ sudo python setup.py 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:
- 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://github.com/hallettj/jslint.vim.git $ cd jslint.vim $ rake install
Then you can run jslint easily from within Vim:
:JSLint
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.
February 12, 2010 at 1:18 PM
For the record, I would LOVE it if you hacked JSLint to do inline highlighting.
May 30, 2011 at 11:08 PM
PROTIP:
To install pyflakes you can run:
sudo pip install git+git://github.com/kevinw/pyflakes.git
Enjoy
January 1, 2024 at 3:45 PM
Appreciate yyour blog post