no magic – just tricks

JSLint with SpiderMonkey

I’ve talked about SpiderMonkeybefore. Being able to instantly evaluate JavaScript code is great but you can use FireBug for that. I argued that the main reason to use SpiderMonkey is to script the command-line. Integrating with JSLint is an example of using your tools intelligently.

JSLint

JSLint is a tool that “looks for problems in JavaScript programs”. Here’s a list of things JSLint looks for (full list):

missing semicolons

missing curly braces ({})

the use of with

the unfiltered use of for in

the use of eval

the implicit use of global variables

missing break statements

double var definitions

the appropriate use of = and == and ===

unreachable code

JSLint is just a way to check your code. However, JSLint, as it stands, is a textarea on the web:

Every time you edit your code, do you want to go jslint.com, paste only the relevant portion of your code, fix the errors locally, rinse and repeat? Anything that causes friction won’t get done. Let’s minimize that.

With SpiderMonkey

As it turns out, JSLint is a JavaScript program that parses JavaScript (!). Knowing that you can evaluate JavaScript on the command-line with SpiderMonkey, you have all the ingredients you need to automate the process.