Saturday 19 September 2009

Checking Javascript Files With JSLINT in Netbeans

Enough about minifying JavaScript, what about checking JS files with JSLint too.

Try this in NetBeans:-

Download the latest lib from http://code.google.com/p/jslint4java/ and put in your ant/lib directory or on the class path. I put it in the netbeans project folder in the example.

Override the pre-compile ant target in your netbeans build.xml so that it looks something like the following example, substituting the class path and includes as appropriate:-



When you build your web application the chosen JavaScript files will be run through the JSLint ant task and checked for errors, the build will fail if any problems are found.

This has saved me hours of debugging JavaScript especially when using cross browser JS libs such as EXTJs.


7 comments:

Ido said...

Very cool.
When we can have it as a plug-in? ;)

Unknown said...

Ooooh, thanks for the mention! Glad it was easy to get up and running…

Neil's Dev Stuff said...

Ido, a plugin would be great, however it is so simple to setup is a plugin really required?

Anonymous said...

All overrides like this are garbage, Netbeans has to get off its butt and do things right or the web developers will continue to leave.

Neil's Dev Stuff said...

I am just a netbeans user mate, tell the netbeans guys, or better still write a plugin and share something positive.

Andrew said...

does this work for Netbeans PHP projects? I'm not really familiar with Java/Ant stuff, but I use a JSLint plugin for visual studio at work and would like to do something similar in Netbeans so that I can run jslint on JS files in my project.

I've posted twice in forums on netbeans and PHP and nobody seems to have an answer on how to do it. :(

Neil's Dev Stuff said...

Hi yeah I dont see why it shouldnt, I dont use PHP, however netbeans uses ant to build all projects so it should work on your php projects too.