• About

    Twinapex Blog is the voice of mobile and Internet experts. We tell tales about our exciting life in the world where communication methods convergence and you can access whatever information you wish, wherever, on whichever device you want.

    If you find us interesting and talented and you are looking for developers, please contact us and we might just be able to help you.

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Verifying Javascript files with JSLint from Eclipse IDE

Posted on March 27, 2008  by Mikko Ohtamaa
Filed Under Uncategorized, javascript

With Web 2.0, Javascript has gained a great foothold in the web development. Javascript, which was originally indented to be few lines of interactivity here and there, is now used for full-blown UI frameworks like Ext JS and Dojo. Because its toy background, Javascript is not the easiest language to debug. Also, the lovely phenomenon known as browser wars has ensured that professional Javascript development is PITA due to browser incompatibilities – It seconds the Symbian C++ embedded programming if you know what I mean.

Javascript is executed run-time. Thus, any errors cannot be cached until the code is run. JSLint is a verifier tool which checks Javascript syntax offline. Of course, it cannot detect application logic errors, but it makes sure that you don’t have cross-browser compability problems in your Javascript syntax. Maybe the most famous of these problems is the extra comma before the list termination which is ok for Firefox, but kills the page on Internet Explorer.

Some argue that this does not really catch bugs and instead a comprehensive unit-test suite should be used. This might be a requirement for a platform level Javascript library code, but it is often an overkill for your little site with some flashy dialog windows.

Installing JSLint

JSLint itself is written in Javascript. So you need to offline Javascript interpreter to run it. On Linux there exists Rhino. On Ubuntu, Rhino package is broken. and you need to download the orignal Rhino JAR from here and copy it to /usr/share/java.

sudo apt-get install rhino # Note https://bugs.launchpad.net/ubuntu/+source/rhino/+bug/93885

Then get JSLint offline version from here.

Running JSLint straight from the Eclipse

We use JSEclipse plug-in in Eclipse for Javascript development. Thus, it is convenient to to execute JSLint directly from the Eclipse IDE.

Drag and drop jslint.js to your project/scripts folder in Eclipse.

Create a new External tool like in the example below.

screenshot-external-tools.png

Then you can run it by just clicking “run external tool” icon. Output comes to the console window.

screenshot-pydev-nurse-source-server-media-js-ui-mapjs-eclipse-sdk.png

Checking all Javascript files during unit test

verify_javascript.bash can be executed from shell and it checks all JS files in your project. This is a nice feature to integrate to your unit test cycle.

Example:

$ bash scripts/verify_javascript.bash source/server/media/jssource/server/media/js/jquery.js

Lint at line 11 character 30: Expected '{' and instead saw 'var'.

...
 

Other posts by Mikko Ohtamaa

 

Comments

5 Responses to “Verifying Javascript files with JSLint from Eclipse IDE”

  1. Do you validate your JavaScript code? - Robert’s talk - Web development and Internet trends on April 17th, 2008 12:18 pm
    Gravatar

    [...] Verifying Javascript files with JSLint from Eclipse IDE [...]

     
  2. Markus on June 26th, 2008 7:25 pm
    Gravatar

    Awesome! Thanks a lot!
    I configured Windows Eclipse like this:
    copy js.jar und jslint.js to [somedir]
    Location: [java_home]\bin\java.exe
    Working Dir: [somedir]
    Arguments: -jar js.jar [somedir]/jslint.js ${resource_loc}

     
  3. REVERT TO CONSOLE » Blog Archive » Running JSLint From Within Eclipse Using Rhino on September 6th, 2008 12:09 am
    Gravatar

    [...] Mikko Ohtamaa provides a nice explanation of how to execute JSLint on a javascript file from within eclipse, using Rhino. [...]

     
  4. michael » JSLint in Eclipse nutzen on October 22nd, 2008 4:08 pm
    Gravatar

    [...] Ohtamaa zeigt hier, wie das bekannte JSLint direkt beim Entwickeln von Javascript in Eclipse (Ich nutze Aptana, hat [...]

     
  5. Steve on November 12th, 2008 9:02 pm
    Gravatar

    The rhino package is fixed in Ubuntu 8.04 Hardy

     

Leave a Reply