<!DOCTYPE html>
<html>
<head>
<title>jslint4java ant task</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="jslint4java.css" type="text/css" rel="stylesheet" />
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
</head>
<body>
<h1>jslint4java ant task</h1>
<p>
jslint4java provides an <a href="http://ant.apache.org/">ant</a> task so
that it can be invoked automatically as part of your build procedure. For
more detail on precisely what is checked, please see
<a href="http://jslint.com/lint.html">the original documentation</a>.
</p>
<p>jslint4java requires Java 5 and ant 1.7.</p>
<h2 id="parameters">Parameters</h2>
<table>
<tr>
<th> Attribute </th>
<th> Description</th>
<th> Required? </th>
</tr>
<tr>
<td> encoding </td>
<td> Specify the encoding of the JavaScript files. Defaults to system encoding. </td>
<td> No </td>
</tr>
<tr>
<td> haltOnFailure </td>
<td> Should the build stop if JSLint reports an error? Defaults to true. </td>
<td> No </td>
</tr>
<tr>
<td> options </td>
<td> A comma separated list of options to pass to JSLint. </td>
<td> No </td>
</tr>
</table>
<p>
The valid list of options is defined by the
<a href="apidoc/com/googlecode/jslint4java/Option.html">Option</a> enum,
and comprises of:
</p>
<dl>
<dt>adsafe </dt><dd>If adsafe should be enforced</dd>
<dt>bitwise </dt><dd>If bitwise operators should not be allowed</dd>
<dt>browser </dt><dd>If the standard browser globals should be predefined</dd>
<dt>cap </dt><dd>If upper case html should be allowed</dd>
<dt>css </dt><dd>If css workarounds should be tolerated</dd>
<dt>debug </dt><dd>If debugger statements should be allowed</dd>
<dt>eqeqeq </dt><dd>If === should be required</dd>
<dt>evil </dt><dd>If eval should be allowed</dd>
<dt>forin </dt><dd>If for in statements must filter</dd>
<dt>fragment </dt><dd>If html fragments should be allowed</dd>
<dt>immed </dt><dd>If immediate invocations must be wrapped in parens</dd>
<dt>indent </dt><dd>The number of spaces used for indentation (default is 4)</dd>
<dt>laxbreak </dt><dd>If line breaks should not be checked</dd>
<dt>newcap </dt><dd>If constructor names must be capitalized</dd>
<dt>nomen </dt><dd>If names should be checked</dd>
<dt>on </dt><dd>If html event handlers should be allowed</dd>
<dt>onevar </dt><dd>If only one var statement per function should be allowed</dd>
<dt>passfail </dt><dd>If the scan should stop on first error</dd>
<dt>plusplus </dt><dd>If increment/decrement should not be allowed</dd>
<dt>regexp </dt><dd>If the . should not be allowed in regexp literals</dd>
<dt>rhino </dt><dd>If the rhino environment globals should be predefined</dd>
<dt>safe </dt><dd>If use of some browser features should be restricted</dd>
<dt>sidebar </dt><dd>If the system object should be predefined</dd>
<dt>strict </dt><dd>Require the "use strict"; pragma</dd>
<dt>sub </dt><dd>If all forms of subscript notation are tolerated</dd>
<dt>undef </dt><dd>If variables should be declared before used</dd>
<dt>white </dt><dd>If strict whitespace rules apply</dd>
<dt>widget </dt><dd>If the yahoo widgets globals should be predefined</dd>
</dl>
<p>
If a parameter is required (as in the case of <em>indent</em>), then it can
be supplied by appending an equals and the value. e.g. <code>indent=2</code>.
</p>
<h2 id="Parameters_specified_as_nested_elements">Parameters specified as nested elements</h2>
<h3 id="resource-collection">resource collection</h3>
<p>
Any kind of
<a href="http://ant.apache.org/manual/CoreTypes/resources.html#collection">resource collection</a>
may be specified as a subelement. Most of the time, this will mean a
<a href="http://ant.apache.org/manual/CoreTypes/fileset.html">fileset</a>.
</p>
<h3 id="formatter">formatter</h3>
<p>
Zero or more formatter elements may be specified in order to control
output from jslint. Each formatter element has two attributes.
</p>
<table>
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
<td> type </td>
<td> Either <tt>plain</tt> or <tt>xml</tt>. </td>
<td> Yes </td>
</tr>
<tr>
<td> destfile </td>
<td> A location to write the output to. Defaults to the console. </td>
<td> No </td>
</tr>
</table>
<p>
If no formatter elements are present, then no output will be produced.
However, the build will still fail if the validation fails.
</p>
<h2 id="examples">Examples</h2>
<p>
First, you need to define the task in your build file.
</p>
<pre class="prettyprint" id="example-taskdef"> <taskdef name="jslint"
classname="com.googlecode.jslint4java.ant.JSLintTask"
classpath="/path/to/jslint4java-1.3.jar" /></pre>
<p>
You may also use the antlibs facility to pull in JSLint.
</p>
<pre class="prettyprint" id="example-xmlns"> <project xmlns:jsl="antlib:com.googlecode.jslint4java">
…
</project></pre>
<p>
Doing so will require you to access the <tt>jslint</tt> task as
<tt>jsl:jslint</tt>.
</p>
<p>
To check a directory for all <tt>.js</tt> files, and emit all errors to
the console:
</p>
<pre class="prettyprint" id="example-all-js"> <jslint>
<formatter type="plain" />
<fileset dir="web/js" includes="*.js" />
</jslint></pre>
<p>
To check a directory for all <tt>.js</tt> files, excluding packed files.
Send any problems to a file <tt>jslint.out</tt>.
</p>
<pre class="prettyprint" id="example-plain-file"> <jslint>
<formatter type="plain" destfile="${build.dir}/jslint.out" />
<fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" />
</jslint></pre>
<p>
To check a directory of JavaScript files, whilst warning about whitespace
issues and undefined variables. Send the errors to the console, and also
emit an XML report to the build directory.
</p>
<pre class="prettyprint" id="example-xml"> <jslint options="undef,white">
<formatter type="plain" />
<formatter type="xml" destfile="${build.dir}/jslint.xml" />
<fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" />
</jslint></pre>
<script type="text/javascript">prettyPrint()</script>
</body>
</html>