1. The basics
npm install -g jslint
Once installed, you can fire it like:
$ jslint my_script.js
Most likely it’ll produce a lot of errors/warnings unless you already write code in a jslint-compliant fashion. There are some options you might want to add:
$ jslint --eqeq --white my_script.js
- –eqeq: tolerant == and !=
- –white: doesn’t enforce strict whitespace rules, for example, doesn’t require spaces around =’s
See the jslint doc site for a complete list of options.
2. Run jslint directly from vim
If you are like me – a vim nut, you might want to integrate jslint into vim, add the following into your ~/.vimrc
command Jslint !jslint --white --eqeq % nnoremap <leader>j :Jslint<CR>
To activate jslint while your are inside vim, simply hit \j in command mode. Special thanks to http://blog.sanctum.geek.nz/series/unix-as-ide/ for the vim integration tip.