Sunday, November 29, 2009

Check your scripts with JSLint on Rails

Here's how you use it:

  1. Make sure you have Java installed (5.0 or later) – it's required to run Rhino.
  2. Install the plugin:
    ./script/plugin install git://github.com/psionides/jslint_on_rails.git
  3. Run the rake task:
    rake jslint

Voila :) That's all you need to check your JS code. You will get a result like this (if everything goes well):

Running JSLint:

checking public/javascripts/Event.js... OK
checking public/javascripts/Map.js... OK
checking public/javascripts/Marker.js... OK
checking public/javascripts/Reports.js... OK

No JS errors found.

If you've messed up something, you will get such results instead:

Running JSLint:

checking public/javascripts/Event.js... 2 errors:

Lint at line 24 character 15: Use '===' to compare with 'null'.
if (a == null && b == null) {

Lint at line 72 character 6: Extra comma.
},

checking public/javascripts/Marker.js... 1 error:

Lint at line 275 character 27: Missing radix parameter.
var x = parseInt(mapX);

Found 3 errors.
rake aborted!
JSLint test failed.

http://psionides.jogger.pl/2009/11/23/check-your-scripts-with-jslint-on-rails/

No comments: