Thursday, October 18, 2007

JSLint with ANT

jslint4java:
"This is a java wrapper around the fabulous tool by Douglas Crockford, jslint. It provides a simple interface for detecting potential problems in JavaScript code."


With this tool, batch scan JavaScript files with JSLint is a piece of cake. Here is a sample ANT target:

<target name="jslint.src.js" depends="init">
<description>scan javascript files using jslint</description>
<apply executable="java" parallel="false" failonerror="false">
<arg value="-jar" />
<arg file="${tools.dir}/${jslint}" />
<arg value="--bitwise" />
<arg value="--browser" />
<arg value="--undef" />
<arg value="--widget" />
<srcfile />
<sort xmlns:rcmp="antlib:org.apache.tools.ant.types.resources.comparators">
<rcmp:name />
<fileset dir="${web.js.dir}">
<include name="**/*.js" />
<exclude name="**/YUI/**" />
<exclude name="**/*-min.js" />
<exclude name="**/*-debug.js" />
</fileset>
</sort>
</apply>
</target>


For ease of future reference, JSLint output can be redirected to a text file:
ANT jslint.src.js > jslintreport.txt

3 comments:

Anonymous said...

Great

Anonymous said...

can this be run at all with java 1.4.2?

Anonymous said...

Quote:
"jslint4java requires Java 5 and ant 1.6.5"

Source: http://code.google.com/p/jslint4java/wiki/JSLintAntTask