| Verifying Javascript files with JSLint from Eclipse IDEPosted on March 27, 2008 by Mikko OhtamaaFiled Under Uncategorized, javascript
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. Then you can run it by just clicking “run external tool” icon. Output comes to the console window. 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'.
...
|
