Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 796 lines (754 sloc) 40.05 kB
ca120a7 @douglascrockford first commit
authored
1 <html>
2 <head>
3 <title>JSLint: The JavaScript Code Quality Tool</title>
4 <link rel="icon" type="image/gif" href="http://www.JSLint.com/favicon.gif">
5 <style>
6 body {
f637aaa @douglascrockford directive
authored
7 background-color: #EFEADF;
8 margin: 0;
9 padding: 0;
10 }
11 fieldset {
12 background-color: oldlace;
13 box-shadow: 0 0 10px rgba(0, 0, 0, 0.35),
14 inset 0 0 10px rgba(169, 84, 84, 0.75);
15 clear: both;
16 margin: 1.5%;
17 padding: 0;
18 width: 97%;
19 }
20 p {
21 margin: 0;
22 margin-left: 5%;
23 margin-right: 5%;
24 padding-bottom: 1em;
25 }
26 ul {
27 margin-top: 0;
28 }
29
30 h1 {
31 background-color: slategray;
32 color: white;
33 font-family: sans-serif;
34 font-size: 100%;
35 font-style: normal;
36 margin: 0;
37 margin-bottom: 1em;
38 padding: 0.35em;
39 text-align: center;
ca120a7 @douglascrockford first commit
authored
40 }
f637aaa @douglascrockford directive
authored
41 blockquote {
42 margin: 0;
43 margin-left: 15%;
44 margin-right: 5%;
45 padding-bottom: 1em;
46 text-indent: -5%;
47 }
48 ul {
49 margin-left: 7.5%;
1ebebf3 @douglascrockford cleanup
authored
50 }
51 table {
f637aaa @douglascrockford directive
authored
52 margin: 1.5%;
53 border: 0;
1ebebf3 @douglascrockford cleanup
authored
54 }
55 th, td {
56 border: black solid 1pt;
57 padding-left: 10px;
58 padding-right: 10px;
59 vertical-align: top;
60 }
ca120a7 @douglascrockford first commit
authored
61 th {
f637aaa @douglascrockford directive
authored
62 background-color: slategray;
63 color: white;
ca120a7 @douglascrockford first commit
authored
64 }
65 td {
66 background-color: white;
67 }
1ebebf3 @douglascrockford cleanup
authored
68 #top table {
69 margin: 0px;
70 }
71 #top td {
72 background-color: linen;
73 border: 0pt;
74 vertical-align: middle;
75 }
76 ul {
77 list-style-type: square;
78 }
79 input[type="button"] {
80 border: 2px solid black;
81 }
82 a:link {
83 color: darkblue;
84 }
85 a:visited {
86 color: purple;
87 }
88 a:hover {
89 color: blue;
90 text-decoration: underline;
91 }
92 a:active {color: red;
93 }
ca120a7 @douglascrockford first commit
authored
94 </style>
95 </head>
f637aaa @douglascrockford directive
authored
96 <body>
97 <div style="background: url(sweater_70.jpg) no-repeat scroll 0 0;
98 background-color: #C8BEAC; height: 3in; left: 0; position: absolute;
99 top: 0; width: 100%; z-index: -1;">
100 </div><div style="float: left; height: 0.75in; width: 5in;">&nbsp;</div>
101 <div style="background-color: #C8BEAC; float:right; margin: 1em; padding-left: 1em; padding-right: 1em;">
102 <a href="#try">Try it.</a><br>
103 <a href="#options">See the options.</a><br>
104 <a href="http://www.amazon.com/exec/obidos/ASIN/0596517742/wrrrldwideweb"
105 target="_blank">Enjoy&nbsp;<i>The Good Parts</i>.</a><br>
106 <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RDLHY5MSG3LZW">Donate.</a>
107 </div>
108 <div style="background-color: #C8BEAC; float: right; font-family: sans-serif;
109 margin: 1em; padding-left: 1em; padding-right: 1em;">
110 The&nbsp;<a href="http://javascript.crockford.com/">JavaScript</a>&nbsp;Code Quality Tool
111 <br><br>
d3dcb36 @douglascrockford JSLint
authored
112 Warning: <code>JSLint</code> will hurt your feelings. </div>
f637aaa @douglascrockford directive
authored
113 <fieldset>
114 <h1 id=what>What is <code>JSLint</code>?</h1>
115
116 <p><code>JSLint</code>
ca120a7 @douglascrockford first commit
authored
117 is a JavaScript program that looks for problems in JavaScript programs.
118 It is a code quality tool.</p>
119
120 <p>When <a href="http://en.wikipedia.org/wiki/C_programming_language">C</a>
121 was a <a href="http://cm.bell-labs.com/cm/cs/who/dmr/chist.html">young</a>
122 programming language, there were several common programming errors that
123 were not caught by the primitive compilers, so an accessory program called
124 <code><a href="http://en.wikipedia.org/wiki/Lint_programming_tool">lint</a></code>
125 was developed that would scan a source file, looking for problems.</p>
126
127 <p>As the language matured, the definition of the language was
128 strengthened to eliminate some insecurities, and compilers got better
129 at issuing warnings. <code>lint</code> is no longer needed.</p>
130
131 <p><a href="http://javascript.crockford.com/">JavaScript</a> is a young-for-its-age
132 language. It was originally intended to do small tasks in webpages, tasks
f637aaa @douglascrockford directive
authored
133 for which Java was too heavy and clumsy. But JavaScript is a surprisingly capable
ca120a7 @douglascrockford first commit
authored
134 language, and it is now being used in larger projects. Many of the features
f637aaa @douglascrockford directive
authored
135 that were intended to make the language easy to use are troublesome when projects become complicated. A <code>lint</code> for JavaScript is needed: <code>JSLint</code>,
ca120a7 @douglascrockford first commit
authored
136 a JavaScript syntax checker and validator.</p>
137
138 <p><code>JSLint</code> takes a JavaScript source and scans it. If it finds
139 a problem, it returns a message describing the problem and an approximate
140 location within the source. The problem is not necessarily a syntax error,
141 although it often is. <code>JSLint</code> looks at some style conventions
142 as well as structural problems. It does not prove that your program is
143 correct. It just provides another set of eyes to help spot problems.</p>
144
145 <p><code>JSLint</code> defines a professional subset of JavaScript, a stricter
146 language than that defined by <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" target="ecma">Third
147 Edition of the <i>ECMAScript Programming Language Standard</i></a>. The
148 subset is related to recommendations found in <a href="http://javascript.crockford.com/code.html" target="sun"><i>Code
149 Conventions for the JavaScript Programming Language</i></a>. </p>
150 <p>JavaScript is a sloppy language, but inside it there is an elegant, better
151 language. <code>JSLint</code> helps you to program in that better language
d3dcb36 @douglascrockford JSLint
authored
152 and to avoid most of the slop. <code>JSLint</code> will reject programs that browsers will accept because <code>JSLint</code> is concerned with the quality of your code and browsers are not. You should accept all of <code>JSLint</code>'s advice.</p>
6735394 @douglascrockford Cleanup.
authored
153 <p><code>JSLint</code> can operate on JavaScript source, HTML source, CSS source, or <a href="http://www.JSON.org/">JSON</a>
ca120a7 @douglascrockford first commit
authored
154 text.</p>
f637aaa @douglascrockford directive
authored
155 <h1 id=global>Global Variables</h1>
ca120a7 @douglascrockford first commit
authored
156 <p>JavaScript's <a href="http://yuiblog.com/blog/2006/06/01/global-domination/">biggest
157 problem</a> is its dependence on global variables, particularly implied
158 global variables. If a variable is not explicitly declared (usually with
159 the <code>var</code> statement), then JavaScript assumes that the variable
160 was global. This can mask misspelled names and other problems.</p>
161 <p><code>JSLint</code> expects that all variables and functions are declared
162 before they are used or invoked. This allows it to detect implied global
163 variables. It is also good practice because it makes programs easier to
164 read.</p>
165 <p>Sometimes a file is dependent on global variables and functions that
166 are defined elsewhere. You can identify these to <code>JSLint</code> with a <code>var</code> statement that lists the global functions and objects
167 that your program depends on. </p>
168 <p>A global declaration can look like this:</p>
f637aaa @douglascrockford directive
authored
169 <blockquote><code>var getElementByAttribute, breakCycles, hanoi;</code></blockquote>
9f0303c @douglascrockford appear
authored
170 <p>The declaration should appear near the top of the file. It must appear before the use of the variables
ca120a7 @douglascrockford first commit
authored
171 it declares. </p>
172 <p>It is necessary to use a <code>var</code> statement to declare a variable before that variable is assigned to. </p>
d3dcb36 @douglascrockford JSLint
authored
173 <p><code>JSLint</code> also recognizes a <code>/*global*/</code> directive that can indicate to <code>JSLint</code> that variables used in this file were defined in other files. The
f637aaa @douglascrockford directive
authored
174 directive can contain a comma separated list of names. Each name can optionally be followed by a colon and either <code>true</code> or <code>false</code>, <code>true</code> indicating that the variable may be assigned to by this file, and <code>false</code> indicating that assignment is not allowed (which is the default). The directive respects function scope.</p>
ca120a7 @douglascrockford first commit
authored
175 <p id=browser>Some globals can be predefined for you. Select the <i>Assume
176 a browser</i> (<code>browser</code>) <a href="#options">option</a> to
177 predefine the standard global properties that are supplied by web browsers,
178 such as <code>document</code> and <code>addEventListener</code>. It has the same
f637aaa @douglascrockford directive
authored
179 effect as this directive:</p>
180 <blockquote><code>/*global
1ebebf3 @douglascrockford cleanup
authored
181 clearInterval: false, clearTimeout: false, document: false, event: false, frames: false, history: false, Image: false, location: false, name: false, navigator: false, Option: false, parent: false, screen: false, setInterval: false, setTimeout: false, window: false, XMLHttpRequest: false
df39101 @douglascrockford option.browser
authored
182 */</code></blockquote>
f637aaa @douglascrockford directive
authored
183 <p id=devel>Select the
e752a55 @douglascrockford option.node
authored
184 <em>Assume console, alert, ...</em>
ca120a7 @douglascrockford first commit
authored
185 (<code>devel</code>) <a href="#options">option</a> to predefine globals that are useful in development but that should be avoided in production, such as <code>console</code> and <code>alert</code>. It has the same
f637aaa @douglascrockford directive
authored
186 effect as this directive:</p>
187 <blockquote><code>/*global alert: false, confirm: false, console: false, Debug: false, opera: false, prompt: false, WSH: false */</code></blockquote>
706c485 @douglascrockford option.node
authored
188 <p id=node>Select the
e752a55 @douglascrockford option.node
authored
189 <em>Assume Node.js</em>
706c485 @douglascrockford option.node
authored
190 (<code>node</code>) <a href="#options">option</a> to predefine globals that are used in the Node.js environment<code></code>. It has the same
f637aaa @douglascrockford directive
authored
191 effect as this
192 directive:</p>
816fc05 @douglascrockford node
authored
193 <blockquote><code>/*global Buffer: false, clearInterval: false, clearTimeout: false, console: false, exports: false, global: false, module: false, process: false, querystring: false, require: false, setInterval: false, setTimeout: false, __filename: false, __dirname: false */</code></blockquote>
ca120a7 @douglascrockford first commit
authored
194 <p id=rhino>Select the <i>Assume Rhino</i> (<code>rhino</code>) <a href="#options">option</a>
706c485 @douglascrockford option.node
authored
195 to predefine the global properties provided by the Rhino environment.
f637aaa @douglascrockford directive
authored
196 It has the same effect as this directive:</p>
ca120a7 @douglascrockford first commit
authored
197 <blockquote>
198 <code>/*global defineClass: false, deserialize: false, gc: false, help: false, load: false, loadClass: false, print: false, quit: false, readFile: false, readUrl: false, runCommand: false, seal: false, serialize: false, spawn: false, sync: false, toint32: false, version: false */ </code>
199 </blockquote>
200 <p id=windows>Select the <i>Assume Windows</i> (<code>windows</code>)
f637aaa @douglascrockford directive
authored
201 <a href="#options">option</a> to predefine the global properties provided by Microsoft Windows. It has the same effect as this directive:</p>
ca120a7 @douglascrockford first commit
authored
202 <blockquote>
f637aaa @douglascrockford directive
authored
203 <code>/*global ActiveXObject: false, CScript: false, Debug: false, Enumerator: false, System: false, VBArray: false, WScript: false, WSH: false */</code>
ca120a7 @douglascrockford first commit
authored
204 </blockquote>
f637aaa @douglascrockford directive
authored
205 <h1 id=semicolon>Semicolon</h1>
6735394 @douglascrockford Cleanup.
authored
206 <p>JavaScript uses a C-like syntax which requires the use of semicolons to delimit certain
207 statements. JavaScript attempts to make those semicolons optional with a semicolon
208 insertion mechanism. This is dangerous because it can mask errors.</p>
ca120a7 @douglascrockford first commit
authored
209 <p>Like C, JavaScript has <code>++</code> and <code>--</code> and <code>(</code> operators
210 which can be prefixes or suffixes. The disambiguation is done by the semicolon.</p>
211 <p>In JavaScript, a linefeed can be whitespace or it can act as a semicolon.
212 This replaces one ambiguity with another. </p>
213 <p><code>JSLint</code> expects that every statement be followed by <code>;</code> except
214 for <code>for</code>, <code>function</code>, <code>if</code>, <code>switch</code>, <code>try</code>, and
215 <code>while</code>. <code>JSLint</code> does not expect to see unnecessary semicolons or the
216 empty statement.</p>
f637aaa @douglascrockford directive
authored
217 <h1 id=comma>Comma</h1>
ca120a7 @douglascrockford first commit
authored
218 <p>The comma operator can lead to excessively tricky expressions. It can also
219 mask some programming errors.</p>
220 <p><code>JSLint</code> expects to see the comma used as a separator, but not as an
221 operator (except in the initialization and incrementation parts of the <code>for</code>
222 statement). It does not expect to see elided elements in array literals. Extra
223 commas should not be used. A comma should not appear after the last element
224 of an array literal or object literal because it can be misinterpreted by some
225 browsers. </p>
f637aaa @douglascrockford directive
authored
226 <h1 id=scope>Scope</h1>
ca120a7 @douglascrockford first commit
authored
227
228 <p>In many languages, a block introduces a scope. Variables introduced in
229 a block are not visible outside of the block.</p>
230
231 <p>In JavaScript, blocks do not introduce a scope. There is only function-scope.
232 A variable introduced anywhere in a function is visible everywhere in
233 the function. JavaScript's blocks confuse experienced programmers and
234 lead to errors because the familiar syntax makes a false promise.</p>
235
236 <p><code>JSLint</code> expects blocks with <code>function</code>, <code>if</code>,
237 <code>switch</code>, <code>while</code>, <code>for</code>, <code>do</code>,
238 and <code>try</code> statements and nowhere else. </p>
239 <p>In languages with block scope, it is usually recommended that variables
240 be declared at the site of first use. But because JavaScript does not
241 have block scope, it is wiser to declare all of a function's variables
242 at the top of the function. It is recommended that a single <code>var</code>
a27d17c @douglascrockford Tolerate
authored
243 statement be used per function. This can be declined with the <code>vars</code>
ca120a7 @douglascrockford first commit
authored
244 <a href="#options">option</a>.</p>
245
f637aaa @douglascrockford directive
authored
246 <h1 id=required>Required Blocks</h1>
ca120a7 @douglascrockford first commit
authored
247
248 <p><code>JSLint</code> expects that <code>if</code>, <code>while</code>,
249 <code>do</code> and <code>for</code> statements will be made with blocks
250 <code>{</code>that is, with statements enclosed in braces<code>}</code>.</p>
251
252 <p>JavaScript allows an <code>if</code> to be written like this:</p>
253
f637aaa @douglascrockford directive
authored
254 <blockquote><code>if (<i>condition</i><code>)
255 </code><i>statement</i>;</code></blockquote>
ca120a7 @douglascrockford first commit
authored
256
257 <p>That form is known to contribute to mistakes in projects where many programmers
258 are working on the same code. That is why <code>JSLint</code> expects the use of
259 a block:</p>
260
f637aaa @douglascrockford directive
authored
261 <blockquote><code>if (<i>condition</i>) {
ca120a7 @douglascrockford first commit
authored
262 <i>statements</i>;
f637aaa @douglascrockford directive
authored
263 }</code></blockquote>
ca120a7 @douglascrockford first commit
authored
264
265 <p>Experience shows that this form is more resilient.</p>
266
f637aaa @douglascrockford directive
authored
267 <h1 id=expression>Expression Statements</h1>
ca120a7 @douglascrockford first commit
authored
268 <p>An expression statement is expected to be an assignment or a function/method
269 call or <code>delete</code>. All other expression statements are considered
270 to be errors.</p>
f637aaa @douglascrockford directive
authored
271 <h1 id=forin><code>for</code> <code>in</code></h1>
ca120a7 @douglascrockford first commit
authored
272 <p>The <code>for</code> <code>in</code> statement allows for looping through
273 the names of all of the properties of an object. <a href="http://yuiblog.com/blog/2006/09/26/for-in-intrigue/">Unfortunately,
d4189ff @douglascrockford properties
authored
274 it also loops through all of the properties that were inherited through
ca120a7 @douglascrockford first commit
authored
275 the prototype chain.</a> This has the bad side effect of serving up method
d4189ff @douglascrockford properties
authored
276 functions when the interest is in data properties. If a program is written without awareness of this situation, then it can fail.</p>
ca120a7 @douglascrockford first commit
authored
277 <p>The body of every <code>for</code> <code>in</code> statement should be
278 wrapped in an <code>if</code> statement that does filtering. It can select
279 for a particular type or range of values, or it can exclude functions,
280 or it can exclude properties from the prototype. For example,</p>
f637aaa @douglascrockford directive
authored
281 <blockquote><code>for (name in object) {
ca120a7 @douglascrockford first commit
authored
282 if (object.hasOwnProperty(name)) {
283 ....
284 }
285
f637aaa @douglascrockford directive
authored
286 }</code></blockquote>
ca120a7 @douglascrockford first commit
authored
287
f637aaa @douglascrockford directive
authored
288 <h1 id=switch><code>switch</code></h1>
ca120a7 @douglascrockford first commit
authored
289 <p>A <a href="http://yuiblog.com/blog/2007/04/25/id-rather-switch-than-fight/">common
290 error</a> in <code>switch</code> statements is to forget to place a <code>break</code>
291 statement after each case, resulting in unintended fall-through. <code>JSLint</code>
292 expects that the statement before the next <code>case</code> or <code>default</code>
293 is one of these: <code>break</code>, <code>return</code>, or <code>throw</code>.
294 </p>
f637aaa @douglascrockford directive
authored
295 <h1 id=var><code>var</code></h1>
ca120a7 @douglascrockford first commit
authored
296
297 <p>JavaScript allows <code>var</code> definitions to occur anywhere
298 within a function. <code>JSLint</code> is more strict.</p>
299
300 <p><code>JSLint</code> expects that a <code>var</code> will be declared
301 only once, and that it will be declared before it is used.</p>
302 <p><code></code><code>JSLint</code> expects that a <code>function</code>
303 will be declared before it is used.</p>
304 <p><code>JSLint</code> expects that parameters will not also be declared
305 as vars. </p>
306
307 <p><code>JSLint</code> does not expect the <code>arguments</code> array to be declared
308 as a <code>var</code>.</p>
309 <p><code>JSLint</code> does not expect that a var will be defined in a block.
310 This is because JavaScript blocks do not have block scope. This can have
311 unexpected consequences. Define all variables at the top of the function.</p>
312
f637aaa @douglascrockford directive
authored
313 <h1 id=with><code>with</code></h1>
ca120a7 @douglascrockford first commit
authored
314
315 <p>The <code>with</code> statement was intended to provide a shorthand in accessing
d4189ff @douglascrockford properties
authored
316 properties in deeply nested objects. Unfortunately, it behaves <a href="http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/">very
317 badly</a> when setting new properties. Never use the <code>with</code> statement. Use
ca120a7 @douglascrockford first commit
authored
318 a <code>var</code> instead.</p>
319
320 <p><code>JSLint</code> does not expect to see a <code>with</code> statement.</p>
321
f637aaa @douglascrockford directive
authored
322 <h1 id=assignment>=</h1>
ca120a7 @douglascrockford first commit
authored
323 <p><code>JSLint</code> does not expect to see an assignment statement in
324 the condition part of an <code>if</code> or <code>for</code> or <code>while</code>
325 <code></code> or <code>do</code> statement. This is because it is more
326 likely that </p>
f637aaa @douglascrockford directive
authored
327 <blockquote><code>if (a = b) {
ca120a7 @douglascrockford first commit
authored
328 ...
f637aaa @douglascrockford directive
authored
329 }</code></blockquote>
ca120a7 @douglascrockford first commit
authored
330 <p>was intended to be </p>
f637aaa @douglascrockford directive
authored
331 <blockquote><code>if (a == b) {
ca120a7 @douglascrockford first commit
authored
332 ...
f637aaa @douglascrockford directive
authored
333 }</code></blockquote>
ca120a7 @douglascrockford first commit
authored
334 <p>It is difficult to write correct programs while using idioms that are
9d80d80 @douglascrockford asignment unwrapped
authored
335 hard to distinguish from obvious errors.</p>
f637aaa @douglascrockford directive
authored
336 <h1 id=eqeq>== and !=</h1>
ca120a7 @douglascrockford first commit
authored
337 <p>The <code>==</code> and <code>!=</code> operators do type coercion before
338 comparing. This is bad because it causes <code>' \t\r\n' == 0</code> to
d3dcb36 @douglascrockford JSLint
authored
339 be <code>true</code>. This can mask type errors. <code>JSLint</code> cannot reliably determine if == is being used correctly, so it is best to not use <code>==</code> and != at all and to always use the more reliable <code>===</code> and <code>!==</code> operators instead. </p>
ca120a7 @douglascrockford first commit
authored
340 <p align="left">If you only care that a value is <i>truthy</i> or <i>falsy</i>,
341 then use the short form. Instead of </p>
f637aaa @douglascrockford directive
authored
342 <blockquote><code>(foo != 0)</code></blockquote>
ca120a7 @douglascrockford first commit
authored
343 <p align="left">just say </p>
f637aaa @douglascrockford directive
authored
344 <blockquote><code>(foo)</code></blockquote>
ca120a7 @douglascrockford first commit
authored
345 <p align="left">and instead of</p>
f637aaa @douglascrockford directive
authored
346 <blockquote><code>(foo == 0)</code></blockquote>
ca120a7 @douglascrockford first commit
authored
347 <p align="left"> say</p>
f637aaa @douglascrockford directive
authored
348 <blockquote><code>(!foo)</code></blockquote>
ba257de @douglascrockford eqeq
authored
349 <p>There is an <code>eqeq</code> <a href="#options">option</a> that allows the use of <code>==</code> and <code>!=</code>.</p>
f637aaa @douglascrockford directive
authored
350 <h1 id=labels>Labels</h1>
ca120a7 @douglascrockford first commit
authored
351 <p>JavaScript allows any statement to have a label, and labels have a
352 separate name space. <code>JSLint</code> is more strict.</p>
353
354 <p><code>JSLint</code> expects labels only on statements that interact
355 with <code>break</code>: <code>switch</code>, <code>while</code>,
356 <code>do</code>, and <code>for</code>. <code>JSLint</code> expects that labels
357 will be distinct from vars and parameters.</p>
358
f637aaa @douglascrockford directive
authored
359 <h1 id=unreachable>Unreachable Code</h1>
ca120a7 @douglascrockford first commit
authored
360 <p><code>JSLint</code> expects that
361 a <code>return</code>, <code>break</code>, <code>continue</code>,
362 or <code>throw</code> statement will be followed by
363 a <code>}</code> or <code>case</code> or <code>default</code>.</p>
364
f637aaa @douglascrockford directive
authored
365 <h1 id=pluses>Confusing Pluses and Minuses</h1>
ca120a7 @douglascrockford first commit
authored
366
367 <p><code>JSLint</code> expects that <code>+</code> will not be followed by
368 <code>+</code> or <code>++</code>, and that <code>-</code> will not be followed
369 by <code>-</code> or <code>--</code>. A misplaced space can turn <code>+ +</code> into <code>++</code>, an error that is difficult to see. Use parens to avoid confusion..</p>
f637aaa @douglascrockford directive
authored
370 <h1 id=inc><code>++</code> and <code>--</code></h1>
ca120a7 @douglascrockford first commit
authored
371 <p>The <code>++</code> <small>(increment)</small> and <code>--</code> <small>(decrement)</small>
372 operators have been known to contribute to bad code by encouraging excessive
373 trickiness. They are second only to faulty architecture in enabling to
44eec74 @douglascrockford Adrian
authored
374 viruses and other security menaces. Also, preincrement/postincrement confusion can produce off-by-one errors that are extremely difficult to diagnose. There is a <code>plusplus</code> <a href="#options">option</a>
a27d17c @douglascrockford Tolerate
authored
375 that allows the use of these operators.</p>
f637aaa @douglascrockford directive
authored
376 <h1 id=bitwise>Bitwise Operators</h1>
ca120a7 @douglascrockford first commit
authored
377 <p>JavaScript does not have an integer type, but it does have bitwise operators.
378 The bitwise operators convert their operands from floating point to integers
379 and back, so they are not as efficient as in C or other languages. They
380 are rarely useful in browser applications. The similarity to the logical
381 operators can mask some programming errors. The <code>bitwise</code> <a href="#options">option</a>
a27d17c @douglascrockford Tolerate
authored
382 allows the use of these operators: <code>&lt;&lt; &gt;&gt; &gt;&gt;&gt;
ca120a7 @douglascrockford first commit
authored
383 ~ &amp; |</code>.</p>
f637aaa @douglascrockford directive
authored
384 <h1 id=evil><code>eval</code> is evil</h1>
ca120a7 @douglascrockford first commit
authored
385 <p>The <code>eval</code> function (and its relatives, <code>Function</code>,
386 <code>setTimeout</code>, and <code>setInterval</code>) provide access
387 to the JavaScript compiler. This is sometimes necessary, but in most cases
388 it indicates the presence of extremely bad coding. The <code>eval</code>
389 function is the most misused feature of JavaScript.</p>
390
f637aaa @douglascrockford directive
authored
391 <h1 id=void><code>void</code></h1>
ca120a7 @douglascrockford first commit
authored
392 <p>In most C-like languages, <code>void</code> is a type. In
393 JavaScript, <code>void</code> is a prefix operator that always
394 returns <code>undefined</code>. <code>JSLint</code> does not expect to
395 see <code>void</code> because it is confusing and not very useful.</p>
396
f637aaa @douglascrockford directive
authored
397 <h1 id=regexp>Regular Expressions</h1>
ca120a7 @douglascrockford first commit
authored
398 <p>Regular expressions are written in a terse and cryptic notation. <code>JSLint</code>
399 looks for problems that may cause portability problems. It also attempts
400 to resolve visual ambiguities by recommending explicit escapement.</p>
401 <p>JavaScript's syntax for regular expression literals overloads the <code>/</code>
402 character. To avoid ambiguity, <code>JSLint</code> expects that the character
403 preceding a regular expression literal is a <code>(</code> or <code>=</code>
404 or <code>:</code> or <code>,</code> character. </p>
f637aaa @douglascrockford directive
authored
405 <h1 id=new>Constructors and <code>new</code></h1>
ca120a7 @douglascrockford first commit
authored
406 <p>Constructors are functions that are designed to be used with the <code>new</code>
407 prefix. The <code>new</code> prefix creates a new object based on the
408 function's <code>prototype</code>, and binds that object to the function's
409 implied <code>this</code> parameter. If you neglect to use the <code>new</code>
410 prefix, no new object will be made and <code>this</code> will be bound
411 to the global object. This is a <a href="http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/">serious
412 mistake</a>.</p>
413 <p><code>JSLint</code> enforces the convention that constructor functions
414 be given names with initial uppercase. <code>JSLint</code> does not expect
415 to see a function invocation with an initial uppercase name unless it
416 has the <code>new</code> prefix. <code>JSLint</code> does not expect to
417 see the <code>new</code> prefix used with functions whose names do not
a27d17c @douglascrockford Tolerate
authored
418 start with initial uppercase. This can be disabled with the <code>newcap</code>
ca120a7 @douglascrockford first commit
authored
419 <a href="#options">option</a>.</p>
420 <p><code>JSLint</code> does not expect to see the wrapper forms <code>new Number</code>,
421 <code>new String</code>, <code>new Boolean</code>. </p>
f637aaa @douglascrockford directive
authored
422 <p><code>JSLint</code> does not expect to see <code>new Object</code>. Use <code>{}</code>
423 instead. </p>
424 <p><code>JSLint</code> does not expect to see <code>new Array</code>. Use <code>[]</code>
425 instead.</p>
426 <h1 id=properties>Properties</h1>
598e67f @douglascrockford /*properties */
authored
427 <p>Since JavaScript is a loosely-typed, dynamic-object language, it is not
428 possible to determine at compile time if property names are spelled correctly.
429 <code>JSLint</code> provides some assistance with this.</p>
430 <p>At the bottom of its report, <code>JSLint</code> displays a <code>/*properties*/</code>
f637aaa @douglascrockford directive
authored
431 directive. It contains all of the names and string literals that were used
598e67f @douglascrockford /*properties */
authored
432 with dot notation, subscript notation, and object literals to name the
097ba53 @douglascrockford new look
authored
433 properties of objects. You can look through the list for misspellings. This is to make misspellings
598e67f @douglascrockford /*properties */
authored
434 easier to spot.</p>
f637aaa @douglascrockford directive
authored
435 <p>You can copy the <code>/*properties*/</code> directive into the top of your script file.
598e67f @douglascrockford /*properties */
authored
436 <code>JSLint</code> will check the spelling of all property names against
437 the list. That way, you can have <code>JSLint</code> look for misspellings
097ba53 @douglascrockford new look
authored
438 for you. </p>
598e67f @douglascrockford /*properties */
authored
439 <p>For example,</p>
f637aaa @douglascrockford directive
authored
440 <blockquote><code>/*properties
097ba53 @douglascrockford new look
authored
441 charAt, slice
f637aaa @douglascrockford directive
authored
442 */</code></blockquote>
598e67f @douglascrockford /*properties */
authored
443
f637aaa @douglascrockford directive
authored
444 <h1 id=unsafe>Unsafe Characters</h1>
ca120a7 @douglascrockford first commit
authored
445 <p> There are characters that are handled inconsistently in browsers, and
446 so must be escaped when placed in strings. </p>
f637aaa @douglascrockford directive
authored
447 <blockquote><code>\u0000-\u001f
ca120a7 @douglascrockford first commit
authored
448 \u007f-\u009f
449 \u00ad
450 \u0600-\u0604
451 \u070f
452 \u17b4
453 \u17b5
454 \u200c-\u200f
455 \u2028-\u202f
456 \u2060-\u206f
457 \ufeff
f637aaa @douglascrockford directive
authored
458 \ufff0-\uffff</code></blockquote>
459 <h1 id=not>Not Looked For</h1>
ca120a7 @douglascrockford first commit
authored
460
461 <p><code>JSLint</code> does not do flow analysis to determine that variables are assigned
462 values before used. This is because variables are given a value (<code>undefined</code>)
6735394 @douglascrockford Cleanup.
authored
463 that is a reasonable default for many applications.</p>
ca120a7 @douglascrockford first commit
authored
464
465 <p><code>JSLint</code> does not do any kind of global analysis. It does
466 not attempt to determine that functions used with <code>new</code> are
467 really constructors (<a href="#new">except by enforcing capitalization
d4189ff @douglascrockford properties
authored
468 conventions</a>), or that property names are spelled correctly (<a href="#properties">except
d3dcb36 @douglascrockford JSLint
authored
469 for matching against the <code>/*properties*/</code> directive</a>).</p>
f637aaa @douglascrockford directive
authored
470 <h1 id=html>HTML</h1>
ca120a7 @douglascrockford first commit
authored
471 <p><code>JSLint</code> is able to handle HTML text. It can inspect the JavaScript content
472 contained within <code>&lt;script&gt;</code>...<code>&lt;/script&gt;</code> tags. It
473 also inspects the HTML content, looking for problems that are known to interfere
474 with JavaScript:</p>
475 <ul>
476 <li>All tag names must be in lower case.</li>
477 <li>All tags that can take a close tag (such as <code>&lt;/p&gt;</code>)
478 must have a close tag.</li>
479 <li>All tags are correctly nested.</li>
480 <li>The entity <code>&amp;lt;</code> must be used for literal <code>'&lt;'</code>.</li>
481 </ul>
482 <p><code>JSLint</code> is less anal than the sycophantic conformity demanded
483 by XHTML, but more strict than the popular browsers. </p>
484 <p><code>JSLint</code> also checks for the occurrence of<code> '&lt;/' </code>in
485 string literals. You should always write<code> '&lt;\/' </code>instead.
486 The extra backslash is ignored by the JavaScript compiler but not by the
487 HTML parser. Tricks like this should not be necessary, and yet they are.</p>
488 <p>There is a <code>cap</code> <a href="#options">option</a> that allows
44eec74 @douglascrockford Adrian
authored
489 use of uppercase tag names. There is also an <code>on</code> <a href="#options">option</a>
ca120a7 @douglascrockford first commit
authored
490 that allows the use of inline HTML event handlers.</p>
491 <p>There is a <code>fragment</code> <a href="#options">option</a> that can
492 inspect a well formed HTML fragment. If the <code>adsafe</code> <a href="#options">option</a>
493 is also used, then the fragment must be a <code>&lt;div&gt;</code> that
494 conforms to the <a href="http://www.ADsafe.org/">ADsafe</a> widget rules.</p>
f637aaa @douglascrockford directive
authored
495 <h1 id=css>CSS</h1>
ca120a7 @douglascrockford first commit
authored
496 <p><code>JSLint</code> can inspect CSS files. It expects the first line
497 of a CSS file to be </p>
f637aaa @douglascrockford directive
authored
498 <blockquote><code>@charset &quot;UTF-8&quot;;</code></blockquote>
ca120a7 @douglascrockford first commit
authored
499 <p>This feature is experimental. Please report any problems or limitations.
500 There is a <code>css</code> <a href="#options">option</a> that will tolerate
598e67f @douglascrockford /*properties */
authored
501 some of the non-standard-but-customary workarounds. </p>
ca120a7 @douglascrockford first commit
authored
502
f637aaa @douglascrockford directive
authored
503 <h1 id=options>Options</h1>
ca120a7 @douglascrockford first commit
authored
504 <p><code>JSLint</code> provides several options that control its operation and
505 its sensitivity. In the <a href="http://www.JSLint.com/">web edition</a>, the
a27d17c @douglascrockford Tolerate
authored
506 options are selected with several checkboxes and two fields. </p>
d3dcb36 @douglascrockford JSLint
authored
507 <p>It also provides assistance in constructing <code>/*jslint*/</code> and <code>/*properties*/</code> directives. </p>
ca120a7 @douglascrockford first commit
authored
508 <p>When <code>JSLINT</code> is called as a function, it accepts an <code>option</code> object
509 parameter that allows you to determine the subset of JavaScript that is
510 acceptable to you. The web page version of <code>JSLint</code> at <a href="http://www.JSLint.com/">http://www.JSLint.com/</a>
511 does this for you. </p>
d3dcb36 @douglascrockford JSLint
authored
512 <p>Options can also be specified within a script with a <code>/*jslint*/</code>
475768b @douglascrockford /*properties*/ and /*global*/ now respect function scope
authored
513 directive:</p>
f637aaa @douglascrockford directive
authored
514 <blockquote><code>/*jslint nomen: true, debug: true,
515 evil: false, vars: true */</code></blockquote>
d3dcb36 @douglascrockford JSLint
authored
516 <p>An option directive starts with <code>/*jslint</code>. Notice that
ca120a7 @douglascrockford first commit
authored
517 there is no space before the <code>j</code>. The specification contains
518 a sequence of name value pairs, where the names are <code>JSLint</code>
519 options, and the values are <code>true</code> or <code>false</code>. The
d3dcb36 @douglascrockford JSLint
authored
520 <code>indent</code> <a href="#options">option</a> can take a number. A <code>/*jslint*/</code>
f637aaa @douglascrockford directive
authored
521 directive takes precedence over the <code>option</code> object. The directive respects function scope.</p>
ca120a7 @douglascrockford first commit
authored
522 <table>
523 <tbody>
524 <tr>
525 <th>Description</th>
526 <th><code>option</code></th>
527 <th>Meaning</th>
528 </tr>
529 <tr>
530 <td>ADsafe</td>
531 <td><code>adsafe</code></td>
532 <td><code>true</code> if <a href="http://www.ADsafe.org/">AD<span style="color: blue;">safe</span></a>
f690208 @douglascrockford adsafe is used with the option object, but not with the /*jslint */ c…
authored
533 rules should be enforced. See <a href="http://www.ADsafe.org/">http://www.ADsafe.org/</a>. <code>adsafe</code> is used with the <code>option</code> object, but not
d3dcb36 @douglascrockford JSLint
authored
534 with the <code>/*jslint*/</code> directive. </td>
ca120a7 @douglascrockford first commit
authored
535 </tr>
536 <tr>
a27d17c @douglascrockford Tolerate
authored
537 <td>Tolerate bitwise operators </td>
ca120a7 @douglascrockford first commit
authored
538 <td><code>bitwise</code></td>
a27d17c @douglascrockford Tolerate
authored
539 <td><code>true</code> if bitwise operators should be allowed. <a href="#bitwise"><small>(more)</small></a></td>
ca120a7 @douglascrockford first commit
authored
540 </tr>
541 <tr>
542 <td>Assume a browser </td>
543 <td><code>browser</code></td>
544 <td><code>true</code> if the standard browser globals should be predefined.
545 <a href="#browser"><small>(more)</small></a> </td>
546 </tr>
547 <tr>
548 <td>Tolerate HTML case </td>
549 <td><code>cap</code></td>
44eec74 @douglascrockford Adrian
authored
550 <td><code>true</code> if uppercase HTML should be allowed.</td>
ca120a7 @douglascrockford first commit
authored
551 </tr>
552 <tr>
3c8016e @douglascrockford option.continue
authored
553 <td>Tolerate <code>continue</code></td>
554 <td><code>continue</code></td>
555 <td><code>true</code> if the <code>continue</code> statement should be allowed.</td>
556 </tr>
557 <tr>
ca120a7 @douglascrockford first commit
authored
558 <td>Tolerate CSS workarounds</td>
559 <td><code>css</code></td>
560 <td><code>true</code> if CSS workarounds should be tolerated. <a href="#css"><small>(more)</small></a></td>
561 </tr>
562 <tr>
563 <td>Tolerate debugger statements</td>
564 <td><code>debug</code></td>
565 <td><code>true</code> if <code>debugger</code> statements should be
566 allowed. Set this option to <code>false</code> before going into production.</td>
567 </tr>
568 <tr>
569 <td>Assume <code>console</code>, <code>alert</code>, ...</td>
570 <td><code>devel</code></td>
571 <td><code>true</code> if browser globals that are useful in development should be
ef3710d @douglascrockford more
authored
572 predefined. <small>(<a href="#devel">more</a>)</small></td>
ca120a7 @douglascrockford first commit
authored
573 </tr>
574 <tr>
ba257de @douglascrockford eqeq
authored
575 <td>Tolerate <code>==</code> and <code>!=</code></td>
576 <td><code>eqeq</code></td>
ef3710d @douglascrockford more
authored
577 <td><code>true</code> if the <code>==</code> and <code>!=</code> operators should be tolerated. <small>(<a href="#eqeq">more</a>)</small></td>
1ebebf3 @douglascrockford cleanup
authored
578 </tr>
ba257de @douglascrockford eqeq
authored
579 <tr>
5675d2c @douglascrockford http://tech.groups.yahoo.com/group/jslint_com/message/1730
authored
580 <td>Tolerate ES5 syntax</td>
581 <td><code>es5</code></td>
1ebebf3 @douglascrockford cleanup
authored
582 <td><code>true</code> if ES5 syntax should be allowed.
583 It is likely that programs using this option will produce syntax errors on ES3 systems.</td>
ca120a7 @douglascrockford first commit
authored
584 </tr>
585 <tr>
586 <td>Tolerate <code>eval</code> </td>
587 <td><code>evil</code></td>
588 <td><code>true</code> if <code>eval</code> should be allowed. <a href="#evil"><small>(more)</small></a></td>
589 </tr>
590 <tr>
591 <td>Tolerate unfiltered for in </td>
592 <td><code>forin</code></td>
593 <td><code>true</code> if unfiltered <code>for</code> <code>in</code>
594 statements should be allowed. <a href="#forin"><small>(more)</small></a></td>
595 </tr>
596 <tr>
597 <td>Tolerate HTML fragments </td>
598 <td><code>fragment</code></td>
599 <td><code>true</code> if HTML fragments should be allowed. <a href="#html"><small>(more)</small></a></td>
600 </tr>
601 <tr>
5675d2c @douglascrockford http://tech.groups.yahoo.com/group/jslint_com/message/1730
authored
602 <td>Strict white space indentation</td>
603 <td><code>indent</code></td>
4310f67 @douglascrockford indent
authored
604 <td>The number of spaces used for indentation (default is 4).</td>
ca120a7 @douglascrockford first commit
authored
605 </tr>
606 <tr>
5675d2c @douglascrockford http://tech.groups.yahoo.com/group/jslint_com/message/1730
authored
607 <td>Maximum number of errors</td>
608 <td><code>maxerr</code></td>
0c4a9d6 @douglascrockford .
authored
609 <td>The maximum number of warnings reported. (default is 50)</td>
ca120a7 @douglascrockford first commit
authored
610 </tr>
611 <tr>
612 <td>Maximum line length</td>
613 <td><code>maxlen</code></td>
0c4a9d6 @douglascrockford .
authored
614 <td>The maximum number of characters in a line.</td>
ca120a7 @douglascrockford first commit
authored
615 </tr>
616 <tr>
a27d17c @douglascrockford Tolerate
authored
617 <td>Tolerate uncapitalized constructors</td>
ca120a7 @douglascrockford first commit
authored
618 <td><code>newcap</code></td>
a27d17c @douglascrockford Tolerate
authored
619 <td><code>true</code> if Initial Caps with constructor
620 functions is optional. <a href="#new"><small>(more)</small></a></td>
ca120a7 @douglascrockford first commit
authored
621 </tr>
622 <tr>
706c485 @douglascrockford option.node
authored
623 <td>Assume Node.js</td>
624 <td><code>node</code></td>
0c4a9d6 @douglascrockford .
authored
625 <td><code>true</code> if Node.js globals should be predefined. <a href="#node"><small>(more)</small></a></td>
706c485 @douglascrockford option.node
authored
626 </tr>
627 <tr>
a27d17c @douglascrockford Tolerate
authored
628 <td>Tolerate dangling _ in identifiers </td>
706c485 @douglascrockford option.node
authored
629 <td><code>nomen</code></td>
0c4a9d6 @douglascrockford .
authored
630 <td><code>true</code> if names should not be checked for initial or trailing underbars.</td>
706c485 @douglascrockford option.node
authored
631 </tr>
632 <tr>
ca120a7 @douglascrockford first commit
authored
633 <td>Tolerate HTML event handlers </td>
634 <td><code>on</code></td>
635 <td><code>true</code> if HTML event handlers should be allowed. <a href="#html"><small>(more)</small></a></td>
636 </tr>
637 <tr>
638 <td>Stop on first error </td>
639 <td><code>passfail</code></td>
640 <td><code>true</code> if the scan should stop on first error.</td>
641 </tr>
642 <tr>
a27d17c @douglascrockford Tolerate
authored
643 <td>Tolerate <code>++</code> and <code>--</code> </td>
ca120a7 @douglascrockford first commit
authored
644 <td><code>plusplus</code></td>
645 <td><code>true</code> if <code>++</code> and <code>--</code> should
a27d17c @douglascrockford Tolerate
authored
646 be allowed. <a href="#inc"><small>(more)</small></a></td>
ca120a7 @douglascrockford first commit
authored
647 </tr>
648 <tr>
649 <td>Predefined <small>( , separated)</small></td>
650 <td><code>predef</code></td>
6735394 @douglascrockford Cleanup.
authored
651 <td>An array of strings, the names of predefined global variables, or an object whose keys are global variable names, and whose values are booleans that determine if each variable is assignable (also see <a href="#global">global</a>). <code>predef</code> is used with the <code>option</code> object, but not
d3dcb36 @douglascrockford JSLint
authored
652 with the <code>/*jslint*/</code> directive. You can also use the <code>var</code>
ca120a7 @douglascrockford first commit
authored
653 statement to declare global variables in a script file.</td>
654 </tr>
655 <tr>
a27d17c @douglascrockford Tolerate
authored
656 <td>Tolerate <code>.</code> and <code>[^</code>...<code>]</code>. in /RegExp/ </td>
ca120a7 @douglascrockford first commit
authored
657 <td><code>regexp</code></td>
a27d17c @douglascrockford Tolerate
authored
658 <td><code>true</code> if <code>.</code> and <code>[^</code>...<code>]</code> should be allowed in RegExp
8d1c4eb @douglascrockford clarification
authored
659 literals. They match more material than might be expected, allowing attackers to confuse applications. These forms should not be used when validating in secure applications. </td>
ca120a7 @douglascrockford first commit
authored
660 </tr>
661 <tr>
662 <td>Assume Rhino </td>
663 <td><code>rhino</code></td>
664 <td><code>true</code> if the <a href="http://www.mozilla.org/rhino/">Rhino</a>
665 environment globals should be predefined. <a href="#rhino"><small>(more)</small></a></td>
666 </tr>
667 <tr>
668 <td>Safe Subset </td>
669 <td><code>safe</code></td>
670 <td><code>true</code> if the safe subset rules are enforced. These rules
671 are used by <a href="http://www.ADsafe.org/">ADsafe</a>. It enforces
f690208 @douglascrockford adsafe is used with the option object, but not with the /*jslint */ c…
authored
672 the safe subset rules but not the widget structure rules. <code>safe</code> is used with the <code>option</code> object, but not
d3dcb36 @douglascrockford JSLint
authored
673 with the <code>/*jslint*/</code> directive. </td>
ca120a7 @douglascrockford first commit
authored
674 </tr>
675 <tr>
a27d17c @douglascrockford Tolerate
authored
676 <td> Tolerate missing&nbsp;<code>'use strict'</code>&nbsp;pragma </td>
677 <td><code>sloppy</code></td>
678 <td><code>true</code> if the ES5 <code><a href="http://www.yuiblog.com/blog/2010/12/14/strict-mode-is-coming-to-town/">'use strict';</a></code> pragma
0c4a9d6 @douglascrockford .
authored
679 is not required. Do not use this pragma unless you know what you are doing.</td>
ca120a7 @douglascrockford first commit
authored
680 </tr>
681 <tr>
abf6a09 @douglascrockford option.stupid
authored
682 <td>Tolerate stupidity<br>
683 </td>
684 <td><code>stupid</code></td>
685 <td><code>true</code> if blocking (<code>'...Sync'</code>) methods can be used.</td>
686 </tr>
687 <tr>
ca120a7 @douglascrockford first commit
authored
688 <td>Tolerate inefficient subscripting<br>
689 </td>
690 <td><code>sub</code></td>
691 <td><code>true</code> if subscript notation may be used for expressions
692 better expressed in dot notation.</td>
693 </tr>
694 <tr>
49284af @douglascrockford option.todo
authored
695 <td>Tolerate TODO comments<br>
696 </td>
697 <td><code>todo</code></td>
698 <td><code>true</code> if comments starting with <code>TODO</code> should be allowed.</td>
699 </tr>
700 <tr>
a27d17c @douglascrockford Tolerate
authored
701 <td> Tolerate misordered definitions </td>
ca120a7 @douglascrockford first commit
authored
702 <td><code>undef</code></td>
8984f62 @douglascrockford This is not available in strict mode.
authored
703 <td><code>true</code> if variables and functions need not be declared before used. This is not available in strict mode.</td>
ca120a7 @douglascrockford first commit
authored
704 </tr>
705 <tr>
0b060c1 @douglascrockford unparam
authored
706 <td> Tolerate unused parameters</td>
707 <td><code>unparam</code></td>
0c4a9d6 @douglascrockford .
authored
708 <td><code>true</code> if warnings should not be given for unused parameters.</td>
0b060c1 @douglascrockford unparam
authored
709 </tr>
710 <tr>
711 <td>Tolerate many&nbsp;<tt>var</tt>&nbsp;statements per function</td>
712 <td><code>vars</code></td>
713 <td><code>true</code> if multiple <code>var</code> statement per function
714 should be allowed. <a href="#scope"><small>(more)</small></a></td>
715 </tr>
716 <tr>
a27d17c @douglascrockford Tolerate
authored
717 <td> Tolerate messy white space</td>
ca120a7 @douglascrockford first commit
authored
718 <td><code>white</code></td>
0b060c1 @douglascrockford unparam
authored
719 <td><code>true</code> if strict whitespace rules should be ignored.</td>
ca120a7 @douglascrockford first commit
authored
720 </tr>
721 <tr>
097ba53 @douglascrockford new look
authored
722 <td>Assume Windows</td>
723 <td><code>windows</code></td>
724 <td><code>true</code> if the Windows globals should be predefined. <a href="#windows"><small>(more)</small></a></td>
ca120a7 @douglascrockford first commit
authored
725 </tr>
726 </tbody>
727 </table>
f637aaa @douglascrockford directive
authored
728 <h1 id=report>Report</h1>
ca120a7 @douglascrockford first commit
authored
729
730 <p>If <code>JSLint</code> is able to complete its scan, it generates a function
731 report. It lists for each function:</p>
732
733 <ul>
734 <li>The line number on which it starts.</li>
735 <li>Its name. In the case of anonymous functions, <code>JSLint</code>
097ba53 @douglascrockford new look
authored
736 will <code>'</code>guess<code>'</code> the name.</li>
ca120a7 @douglascrockford first commit
authored
737 <li>The parameters.</li>
738 <li><i>Closure</i>: The variables and parameters that are declared in
739 the function that are used by its inner functions.</li>
740 <li><i>Variables</i>: The variables that are declared in the function
741 that are used only by the function.</li>
742 <li><i>Exceptions</i>: The variables that are declared by try statements.</li>
743 <li><i>Unused</i>: The variables that are declared in the function that
744 are not used. This may be an indication of an error.</li>
745 <li><i>Outer</i>: Variables used by this function that are declared in
746 another function.</li>
747 <li><i>Global</i>: Global variables that are used by this function. Keep
748 these to a minimum.</li>
749 <li><i>Label</i>: Statement labels that are used by this function.</li>
750 </ul>
d4189ff @douglascrockford properties
authored
751 <p>The report will also include a list of all of the <a href="#properties">property
ca120a7 @douglascrockford first commit
authored
752 names</a> that were used. There is a <a href="msgs.html">list of <code>JSLint</code>
753 messages</a>.</p>
f637aaa @douglascrockford directive
authored
754 <h1 id=feedback>Feedback</h1>
ca120a7 @douglascrockford first commit
authored
755 <p>Please let me know if <code>JSLint</code> is useful for you. Is it too
756 strict? Is there a check or a report that could help you to improve the
eec32d4 @douglascrockford But please
authored
757 quality of your programs?
758 <a href="mailto:douglas@crockford.com">douglas@crockford.com</a>.
759 But please don't ask me to dumb <code>JSLint</code> down or to make it more
760 forgiving of bad practices. You would only be disappointed.</p>
ca120a7 @douglascrockford first commit
authored
761 <p>I intend to continue to adapt <code>JSLint</code> based on your comments.
eec32d4 @douglascrockford But please
authored
762 Keep watching for improvements. Updates are announced at
763 <a href="http://tech.groups.yahoo.com/group/jslint_com/">http://tech.groups.yahoo.com/group/jslint_com/</a>. </p>
ca120a7 @douglascrockford first commit
authored
764
f637aaa @douglascrockford directive
authored
765 <h1 id=try>Try it</h1>
ca120a7 @douglascrockford first commit
authored
766
767 <p><a href="http://www.JSLint.com" target="_blank">Try it.</a> Paste your script
768 into the window and click the
097ba53 @douglascrockford new look
authored
769 <a href="http://www.JSLint.com" target=jslint><button style="
770 background-color: lightsteelblue;
771 border-radius: 16pt;
772 color: black;
773 cursor: pointer;
774 font-family: sans-serif;
775 font-size: 100%;
776 font-style: normal;
777 margin: 0pt;
778 padding-left: 2em;
779 padding-right: 2em;
780 text-align: center;
781 ">JSLint</button></a>
ca120a7 @douglascrockford first commit
authored
782 button. The analysis is done by a script running on your machine.
598e67f @douglascrockford /*properties */
authored
783 Your script is not sent over the network. You can set the <a href="#options">options</a> used. </p>
bdd3576 @douglascrockford k
authored
784 <p>
d3dcb36 @douglascrockford JSLint
authored
785 <code>JSLint</code> is written entirely in JavaScript, so it can run anywhere that JavaScript can run. See for example <a href="http://tech.groups.yahoo.com/group/jslint_com/database?method=reportRows&tbl=1">http://tech.groups.yahoo.com/group/jslint_com/database?method=reportRows&amp;tbl=1</a>.</p>
f637aaa @douglascrockford directive
authored
786 <h1 id=implementation>Implementation</h1>
ca120a7 @douglascrockford first commit
authored
787 <p><code>JSLint</code> uses a <a href="http://javascript.crockford.com/tdop/tdop.html">Pratt
788 Parser (Top Down Operator Precedence)</a>. It is written in JavaScript.
35ec4a5 @douglascrockford groove
authored
789 The full source code is available: <a href="https://github.com/douglascrockford/JSLint">https://github.com/douglascrockford/JSLint</a>.</p>
f637aaa @douglascrockford directive
authored
790 </fieldset>
ca120a7 @douglascrockford first commit
authored
791 <a href="http://www.JSLint.com/"><img src="jslintpill.gif" width="36" height="17" border="0"></a>
792 <a href="http://www.ADsafe.org/"><img src="adsafepill.gif" width="36" height="17" border="0"></a>
793 <a href="http://www.JSON.org/"><img src="jsonpill.gif" width="36" height="17" border="0"></a>
794 </body>
795 </html>
Something went wrong with that request. Please try again.