Home > javascript, jslint, vim > How to write javascript codes more jslint-compliant

How to write javascript codes more jslint-compliant

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 http://blog.sanctum.geek.nz/series/unix-as-ide/ for the vim integration tip.

Categories: javascript, jslint, vim
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: