Monday, 27 May 2013

Hiding Javascript validation errors in Eclipse Juno

So you are working on a project that includes some third party Javascript libraries, and your editor is Eclipse (I'm on Juno, but no doubt this issue affects Indigo or even farther back...) - anyhow, you import the .js file into your nice clean project and bang! The Problems tab shows errors in the script

For example, I get errors with libraries like
Syntax error on token "Invalid Regular Expression Options", no accurate correction available
and handlebars.js (1.0.0.rc4) raises three
Syntax error on token ",", delete this token
Syntax error on token ")", ( expected
Syntax error on token "]", delete this token
and of course the problem is not "real" - it is just Eclipse's implementation of the Javascript validator.

So if you are a braver coder than me you could edit these files and fix the issues and hope that doesn't break any other part of the library :/  OR you can suppress the errors in Eclipse.

However you don't want to suppress all Javascript validation because then you wouldn't see your own errors! (And I make plenty).  So here is how to exclude just the third party libraries...

1. You want to keep all your third party librarries in a different path to your own .js files - I use a js directory, below that I have a lib directory where jquery et al go.  So thats a path like
2. Right click on the Project, navigate thus Properties -> Javascript -> Include Path.

3. Click the Source tab, expand your WebContent node so you can see "Excluded".

4. Select Excluded, click the Edit button, then add an Exclusion pattern of
then click Finish, OK, then do a new build if one doesn't kick off automatically.

Now you should have no more phantom error reports from the third party libraries.