happygiraffe / jslint4java

A Java wrapper around Doug Crockford's marvellous jslint tool.

This URL has Read+Write access

jslint4java / ant.html
100644 213 lines (186 sloc) 8.397 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!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>.
      To get started quickly, see the <a href="#examples">examples</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> jslint </td>
        <td> The path to an alternative <code>jslint.js</code>. If you want to use a newer version than the bundled one. </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="apidocs/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>maxerr </dt><dd>The maximum number of warnings reported (default is 50)/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"> &lt;taskdef name="jslint"
           classname="com.googlecode.jslint4java.ant.JSLintTask"
           classpath="/path/to/jslint4java-${project.version}.jar" /&gt;</pre>
 
    <p>
      You may also use the antlibs facility to pull in JSLint.
    </p>
 
    <pre class="prettyprint" id="example-xmlns"> &lt;project xmlns:jsl="antlib:com.googlecode.jslint4java"&gt;
    …
  &lt;/project&gt;</pre>
 
    <p>
      Doing so will require you to access the <tt>jslint</tt> task as
      <tt>jsl:jslint</tt>. This also means that you have to install
      <code>jslint4java-${project.version}.jar</code> in
      <code>~/.ant/libs</code>.
    </p>
 
    <p>
      If you want to keep the jslint4java jar checked in as part of your
      project, you have to combine the above two approaches. For example,
      assuming you have placed the jar in <code>lib-build</code>:
    </p>
 
    <pre class="prettyprint" id="example-checkedin">&lt;project xmlns:jsl=&quot;antlib:com.googlecode.jslint4java&quot;&gt;
  &lt;path id=&quot;ant.tasks.classpath&quot;&gt;
    &lt;fileset dir=&quot;lib-build&quot; include=&quot;*.jar&quot; /&gt;
  &lt;/path&gt;
  &lt;taskdef uri=&quot;antlib:com.googlecode.jslint4java&quot;
           resource=&quot;com/googlecode/jslint4java/antlib.xml&quot;
           classpathref=&quot;ant.tasks.classpath&quot; /&gt;
  &hellip;
&lt;/project&gt;</pre>
 
    <p>
      Again, this means you have to refer to the task as <code>jsl:jslint</code>.
    </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"> &lt;jslint&gt;
    &lt;formatter type="plain" /&gt;
    &lt;fileset dir="web/js" includes="*.js" /&gt;
  &lt;/jslint&gt;</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"> &lt;jslint&gt;
    &lt;formatter type="plain" destfile="${build.dir}/jslint.out" /&gt;
    &lt;fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" /&gt;
  &lt;/jslint&gt;</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"> &lt;jslint options="undef,white"&gt;
    &lt;formatter type="plain" /&gt;
    &lt;formatter type="xml" destfile="${build.dir}/jslint.xml" /&gt;
    &lt;fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" /&gt;
  &lt;/jslint&gt;</pre>
 
    <script type="text/javascript">prettyPrint()</script>
  </body>
</html>