• JavaScript Lint and other Tools

JavaScript Lint and other Tools

Required reading:  Javascript: The Good Parts by Douglas Crockford.  This book explains why your style and choice of code constructs matter a lot if your goal is to write working code.  


Douglas Crockford's excellent tool enforces style and checks for many unsafe constructs.  His tool is online here.

Douglas no longer distributes a stand-alone version of jslint;  if you want to check your javascript files locally from the commandline, you can try using my short ruby script jslint.rb, which automatically pulls and uses the most recent jslint.js from http://www.jslint.com/jslint.js.  You'll need to install the "rhino" javascript interpreter (other interpreters might work too if you modify the next to last line of the script).  Run jslint.rb --help for usage information.

Issues:  jslint requires things to be defined lexically before use, which isn't a javascript requirement.  It goes hand-in-hand with moving all var declarations to the top of the scope.  It also violates the idea of DRY, which I claim would move one towards putting the declaration and definition in the same place when possible.

JavaScript Lint

Matthias Miller's JavaScript Lint tool has a downloadable version that runs from the commandline, as well as an online version.

Closure Linter

Google's Closure Linter tool enforces the Google JavaScript Style Guide, and in fact can modify code in many cases to match Google's desired style.

Closure Compiler

Google's Closure Compiler optimizes and minifies javascript, but it also checks for illegal JavaScript and potentially unsafe operations.  So even if you don't want to make use of the minification, the warnings and errors are useful.

YUI Compressor

Yahoo's YUI Compressor minifies javascript, but like closure compiler, also checks for code problems.
Randy Sargent,
Sep 19, 2011, 5:25 AM