Titanium Studio and JSlint

JavaScript can sometimes be really tricky. As scripting languages are a bit tricky for static code analyzers, some tools can already provide helpful comments about your code even though they can only understand the syntax.

JSlint is one of these awesome tools and for Titanium developers, it’s super-easy to enable JSlint.

Enabling JSlint is totally easy:

  1. Open the preferences
    Mac OS X: In the menu: Open Titanium Studio → Preferences
    Windows/Linux: In the menu:  Open Help → Preferences
  2. Search for “validation”
  3. Open the Validation item beneath Aptana Studio or Titanium Studio (depends on your version of Studio)
  4. Select JavaScript
  5. Enable JSLint JavaScript Validator

Now, all you have to do is: Open each file once and let Studio run the validator. In the Problems tab (usually below you code editor), you’ll get a bunch of useful comments for your code. Projects that haven’t been developed with JSlint before, will pretty quickly come up with something like this:

Some warnings can easily be turned off:

  • Global variables can be declared as globals (pretty useful if you Ti.include() a lot): /*globals MyGlobal:true*/ can be used to avoid warnings about MyGlobal
  • Warnings about for-in can be disabled like this:
    /*jslint forin:true*/
    for(a in b) {
      /* do something */
    }
    /*jslint forin:false*/
  • Other flags are explained on the JSlint page; most of them, you won’t need.

Happy Hacking!