Archive for the ‘jslint’ Category

How to write javascript codes more jslint-compliant

February 21, 2012 Leave a comment

1. The basics
If you love writing Javascript codes, you should have some kind of syntax validator installed. The one and only tool I am using is jslint, which can be installed in a number of ways, depending on the os and development toolkits available. My favorite way to is to install through npm (provided that node.js is installed, if not, try nvm):
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 for the vim integration tip.

Categories: javascript, jslint, vim