@jslint-org/jslint 2021.10.20 → 2021.11.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/help.html DELETED
@@ -1,1232 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta
6
- name="description"
7
- content="How to use JSLint to reduce the rate of error formation in
8
- JavaScript programs. JSLint recommends using only the good parts of The
9
- ECMAScript Programming Language Standard, Sixth Edition [ES6]."
10
- >
11
- <meta
12
- name="author"
13
- content="Douglas Crockford"
14
- >
15
- <meta name="date" content="2020-09-09"
16
- >
17
- <link
18
- rel="stylesheet"
19
- type="text/css"
20
- href="https://fonts.googleapis.com/css?family=Patua+One"
21
- >
22
- <link
23
- rel="icon"
24
- type="image/png"
25
- href="asset_image_logo_512.svg"
26
- />
27
- <title>JSLint: Help</title>
28
- <style>
29
- @font-face {
30
- font-display: swap;
31
- font-family: "Daley";
32
- font-weight: bold;
33
- src: url("asset_font_daley_bold.woff2") format("woff2");
34
- }
35
- body {
36
- background-color: seashell;
37
- font-family: Palatino, serif;
38
- font-size: 100%;
39
- margin: 0;
40
- padding: 0;
41
- }
42
- #JSLINT_TITLE {
43
- color: darkslategray;
44
- float: left;
45
- font-family: "Daley", monospace;
46
- font-size: 48pt;
47
- margin-left: 12%;
48
- padding: 0;
49
- }
50
-
51
- h1 {
52
- background-color: darkslategray;
53
- color: white;
54
- font-family: "Daley", serif;
55
- font-size: 100%;
56
- font-style: normal;
57
- font-weight: normal;
58
- margin-bottom: 1em;
59
- margin-left: 12%;
60
- margin-right: 12%;
61
- margin-top: 1em;
62
- padding-bottom: 0.25em;
63
- padding-left: 0;
64
- padding-right: 0;
65
- padding-top: 0.25em;
66
- text-align: center;
67
- }
68
- th {
69
- background-color: darkslategray;
70
- color: white;
71
- }
72
- td {
73
- background-color: white;
74
- }
75
- button {
76
- background-color: lightsteelblue;
77
- border: 0;
78
- color: black;
79
- cursor: pointer;
80
- font-family: "Daley", serif;
81
- font-size: 100%;
82
- font-style: normal;
83
- margin-bottom: 0;
84
- margin-left: 0.25em;
85
- margin-right: 0.25em;
86
- margin-top: 0;
87
- padding-left: 1em;
88
- padding-right: 1em;
89
- text-align: center;
90
- }
91
- s {
92
- display: inline-block;
93
- font-family: "Daley", cursive;
94
- font-style: normal;
95
- padding-left: 0.1em;
96
- text-decoration: none;
97
- }
98
- big {
99
- font-size: 50pt;
100
- font-style: normal;
101
- font-weight: normal;
102
- margin-left: 0.125em;
103
- margin-top: -0.2em;
104
- }
105
- code, pre {
106
- font-family: monospace;
107
- font-size: 100%;
108
- font-style: normal;
109
- font-weight: normal;
110
- }
111
- small {
112
- font-style: italic;
113
- }
114
- p {
115
- margin-bottom: 1em;
116
- margin-left: 12%;
117
- margin-right: 12%;
118
- margin-top: 1em;
119
- text-align: justify;
120
- }
121
- blockquote {
122
- margin-bottom: 1em;
123
- margin-left: 18%;
124
- margin-right: 18%;
125
- margin-top: 1em;
126
- }
127
- blockquote div {
128
- margin-left: 2.2em;
129
- }
130
- pre {
131
- margin-bottom: 1em;
132
- margin-left: 18%;
133
- margin-right: 12%;
134
- margin-top: 1em;
135
- }
136
- table blockquote {
137
- margin-left: 0;
138
- margin-right: 6%;
139
- }
140
- ul {
141
- list-style-type: square;
142
- margin-left: 12%;
143
- margin-right: 12%;
144
- }
145
- table {
146
- border: 0;
147
- margin: 1em;
148
- max-width: 76%;
149
- }
150
- th, td {
151
- border: black solid 1pt;
152
- padding-left: 10px;
153
- padding-right: 10px;
154
- vertical-align: top;
155
- }
156
- a:link {
157
- color: darkblue;
158
- }
159
- a:visited {
160
- color: purple;
161
- }
162
- a:hover {
163
- color: blue;
164
- text-decoration: underline;
165
- }
166
- a:active {
167
- color: red;
168
- }
169
- #title {
170
- color: gray;
171
- font-family: "Trebuchet MS", sans-serif;
172
- font-size: 200%;
173
- font-weight: bold;
174
- padding-top: 0.75em;
175
- text-align: center;
176
- text-decoration: none;
177
- }
178
- </style>
179
- </head>
180
- <body>
181
- <a href="https://www.jslint.com/"><div id="JSLINT_TITLE">JSLint</div></a>
182
- <ul style="float: right; margin: 1em; padding-right: 12%;">
183
- <li><a href="https://www.jslint.com/">Try it.</a></li>
184
- <li><a href="https://www.amazon.com/dp/1949815005/wrrrldwideweb">
185
- <i>How JavaScript Works</i> by Douglas Crockford.
186
- </a></li>
187
- </ul>
188
- <div id=title>Help</div>
189
- <br clear=all>
190
- <blockquote>Il semble que la perfection soit atteinte non quand il n&#8217;y a
191
- plus rien &agrave; ajouter, mais quand il n&#8217;y a plus rien &agrave;
192
- retrancher.</blockquote>
193
- <center>
194
- Antoine de Saint-Exupéry
195
- </center>
196
- <center>
197
- <i>Terre des Hommes</i> (1939)
198
- </center>
199
- <h1 id=good>Good Parts</h1>
200
- <p>The Principle of the Good Parts is</p>
201
- <blockquote> If a feature is sometimes useful and sometimes dangerous and if
202
- there is a better option then always use the better option. </blockquote>
203
- <p>JSLint is a JavaScript program that looks for problems in
204
- JavaScript programs. It is a code quality tool.</p>
205
- <p>When <a href="https://en.wikipedia.org/wiki/C_programming_language">C</a> was
206
- a young
207
- programming language, there were several common programming errors that
208
- were not caught by the primitive compilers, so an accessory program called
209
- <code><a href="https://en.wikipedia.org/wiki/Lint_programming_tool">lint</a></code>
210
- was developed that would scan a source file, looking for problems.</p>
211
- <p>As the language matured, the definition of the language was
212
- strengthened to eliminate some insecurities, and compilers got better
213
- at issuing warnings. <code>lint</code> is no longer needed.</p>
214
- <p><a href="https://www.crockford.com/javascript/">JavaScript</a> is a
215
- young-for-its-age language. It was originally intended to do small tasks in
216
- webpages, tasks for which Java was too heavy and clumsy. But JavaScript is
217
- a surprisingly capable language, and it is now being used in larger
218
- projects. Many of the features that were intended to make the language easy
219
- to use are troublesome when projects become complicated. A <code>lint</code>
220
- for JavaScript is needed: JSLint, a JavaScript syntax checker
221
- and validator.</p>
222
- <p>JSLint takes a JavaScript source and scans it. If it finds a
223
- problem, it returns a message describing the problem and an approximate
224
- location within the source. The problem is not necessarily a syntax error,
225
- although it often is. JSLint looks at some style conventions
226
- as well as structural problems. It does not prove that your program is
227
- correct. It just provides another set of eyes to help spot problems.</p>
228
- <p>JSLint defines a professional subset of JavaScript, a stricter
229
- language than that defined by the <i>ECMAScript Programming Language
230
- Standard</i> (the strangely named document that governs JavaScript).
231
- JSLint will reject most legal programs. It is a higher
232
- standard.</p>
233
- <p>JavaScript is a sloppy language, but hidden deep inside there is an elegant,
234
- better language. JSLint helps you to program in that better
235
- language and to avoid most of the slop. JSLint will reject
236
- programs that browsers will accept because JSLint is concerned
237
- with the quality of your code and browsers are not. You should gladly accept
238
- all of JSLint's advice.</p>
239
- <p>JSLint can operate on JavaScript source
240
- or <a href="https://www.json.org/">JSON</a> text.</p>
241
- <h1 id=es6>ECMAScript Sixth Edition</h1>
242
- <p>Some of
243
- ES6&rsquo;s features are good, so JSLint will recognize the good
244
- parts of ES6. </p>
245
- <p>Currently, these features are recognized:</p>
246
- <ul>
247
- <li>The <code>...</code>&nbsp;<small>ellipsis</small> marker in parameter
248
- lists and argument lists, replacing the <code>arguments</code> object
249
- for variadic functions.</li>
250
- <li>The <code>let</code> statement, which is like the <code>var</code>
251
- statement except that it respects block scope.
252
- You may use <code>let</code> or <code>var</code> but not both.</li>
253
- <li>The <code>const</code> statement is like the <code>let</code> statement
254
- except that it disallows the use of assignment on the variable, although
255
- if the value of the variable is mutable, it can still be mutated.
256
- <code>const</code> is preferred to <code>let</code>.
257
- <li>Destructuring of arrays and objects is allowed in parameter lists and on
258
- the left side of <code>let</code>, and <code>const</code>, but not
259
- <code>var</code> or assignment statements, and not deep destructuring
260
- or eliding.</li>
261
- <li>Enhanced object literals, providing shorter forms for function
262
- declaration and properties that are initialized by variables with the
263
- same name.</li>
264
- <li>The fat arrow <code>=></code>&nbsp;<small>fart</small> functions.</li>
265
- <li>The simplest forms of <code>import</code> and <code>export</code>.</li>
266
- <li><code>`</code>Megastring<code>`</code> literals, but not nested
267
- <code>`</code>megastring<code>`</code> literals.</li>
268
- <li>New global functions, such as <code>Map</code>, <code>Set</code>,
269
- <code>WeakMap</code>, and <code>WeakSet</code>.</li>
270
- <li><code>0b</code>- and <code>0o</code>- number literals.</li>
271
- </ul>
272
- <p>The most important new feature of ES6 is proper tail calls. This has no
273
- new syntax, so JSLint doesn&rsquo;t see it. But it makes recursion
274
- much more attractive, which makes loops, particularly <code>for</code>
275
- loops, much less attractive.</p>
276
- <h1 id="import"><code>import export</code></h1>
277
- <p>The ES6 module feature will be an important improvement over JavaScript&rsquo;s
278
- global variables as a means of linking separate files together.
279
- JSLint recognizes a small but essential subset of the module
280
- syntax.</p>
281
- <blockquote>
282
- <p><code>import </code><var>name</var><code> from </code><var>stringliteral</var><code>;</code></p>
283
- <p><code>import {</code><var>name</var><code>} from </code><var>stringliteral</var><code>;</code></p>
284
- <p><code>import(</code><var>string</var><code>).then(</code><var>function</var><code>);</code></p>
285
- <p><code>export default function () {};</code></p>
286
- <p><code>export default function <var>name</var>() {};</code></p>
287
- <p><code>export default </code><var>expression</var><code>;</code></p>
288
- <p><code>export function <var>name</var>() {}</code></p>
289
- <p><code>export </code><var>name</var><code>; // </code> where <var>name</var> is <code>const</code></p>
290
- <p><code>export {</code><var>name</var><code>}</code><code>;</code></p>
291
- </blockquote>
292
- <h1 id=directives>Directives</h1>
293
- <p>JSLint provides three directives that may be placed in a
294
- file to manage JSLint&rsquo;s behavior. Use of these directives is
295
- optional. If they are used, they should be placed in a source file before
296
- the first statement. They are written in the form of a comment, where the
297
- directive name is placed immediately after the opening of the comment before
298
- any whitespace. The three directives are <code>global</code>,
299
- <code>jslint</code>, and <code>property</code>. Directives in a file are
300
- stronger than options selected from the UI or passed with the option object.</p>
301
- <h1 id=global><code>/*global*/</code></h1>
302
- <p>The <code>/*global*/</code> directive is used to specify a set of globals
303
- (usually functions and objects containing functions) that are available to
304
- this file. This was commonly used in browsers to link source files together
305
- before ES6 modules appeared. Use of global variables is strongly
306
- discouraged, but unfortunately web browsers require their use. The
307
- <code>/*global*/</code> directive can only be used when the
308
- <a href="#browser">Assume a browser</a> option is selected.
309
- <p>Each of the names listed will indicate a read-only global variable. The names
310
- are separated by <code>,</code>&nbsp;<small>comma</small>. This directive
311
- should not be used if <code>import</code> or <code>export</code> is used.
312
- This directive inhibits warnings, but it does not declare the names in the
313
- execution environment.
314
- <p>For example:
315
- <blockquote><code>/*global</code>
316
- <div><code>ADSAFE, report, jslint</code></div>
317
- <code>*/</code></blockquote>
318
- <p>instructs JSLint to not give warnings about the global
319
- variables <code>ADsafe</code>, <code>report</code>, and <code>jslint</code>.
320
- However, if any of those names are expected to be supplied by other files
321
- and those other files fail to do so, then execution errors will result. It
322
- is usually better to use top-level variable declarations instead:
323
- <pre> var ADSAFE;
324
- var report;
325
- var jslint; </pre>
326
- <p>Using <code>var</code> in this way allows comparing a global variable to the
327
- <code>undefined</code> value to determine whether it is has been used in the global context.</p>
328
- <h1><code>/*jslint*/</code></h1>
329
- <p>The <code>/*jslint*/</code> directive allows for the control of several
330
- options. These options can also be set from the
331
- <a href="https://www.jslint.com/">jslint.com</a> user interface.</p>
332
-
333
- <center>
334
- <table>
335
- <tbody>
336
- <tr>
337
- <th>Description</th>
338
- <th><code>option</code></th>
339
- <th>Meaning</th>
340
- </tr>
341
- <tr>
342
- <td id="bitwise">Tolerate bitwise operators</td>
343
- <td><code>bitwise</code></td>
344
- <td><code>true</code> if bitwise operators should be allowed. The
345
- bitwise operators are rarely used in JavaScript programs, so it
346
- is usually more likely that <code>&amp;</code> is a mistyping of
347
- <code>&amp;&amp;</code> than that it indicates a bitwise <i>and</i>.
348
- JSLint will give warnings on the bitwise operators
349
- unless this option is selected.</td>
350
- </tr>
351
- <tr>
352
- <td id="browser">Assume a browser </td>
353
- <td><code>browser</code></td>
354
- <td><code>true</code> if the standard browser globals should be
355
- predefined. This option will reject the use of
356
- <code>import</code> and <code>export</code>. This option also
357
- disallows the file form of the <code>&quot;use
358
- strict&quot;</code> pragma. It does not supply
359
- <code>self</code>; you will have to request that unnecessary
360
- alias of the dreaded global object yourself. It adds the same
361
- globals as this directive:
362
- <blockquote><code>/*global </code>
363
- <div><code>
364
- clearInterval, clearTimeout, document, event, FileReader,
365
- FormData, history, localStorage, location, name, navigator,
366
- screen, sessionStorage, setInterval, setTimeout, Storage,
367
- URL, window, XMLHttpRequest
368
- </code></div>
369
- <code>*/</code></blockquote>
370
- </td>
371
- </tr>
372
- <tr>
373
- <td id="convert">Tolerate conversion operators</td>
374
- <td><code>convert</code></td>
375
- <td><code>true</code> if <code>!!</code>, <code>+</code> prefix,
376
- and concatenation with <code>&quot;&quot;</code> are allowed.
377
- The <code>Boolean</code>, <code>Number</code>, and
378
- <code>String</code> functions are preferred</td>
379
- </tr>
380
- <tr>
381
- <td id="couch">Assume <a href="https://couchdb.apache.org/">CouchDB</a></td>
382
- <td><code>couch</code></td>
383
- <td><code>true</code> if
384
- <a href="https://couchdb.apache.org/">Couch DB</a>
385
- globals should be predefined. It adds the same globals as this
386
- directive:
387
- <blockquote><code>/*global </code>
388
- <div><code>emit, getRow, isArray, log, provides, registerType, require,
389
- send, start, sum, toJSON </code></div>
390
- <code> */</code></blockquote></td>
391
- </tr>
392
- <tr>
393
- <td id="devel">Assume in development</td>
394
- <td><code>devel</code></td>
395
- <td><code>true</code> if browser globals that are useful in
396
- development should be predefined, and if <code>debugger</code>
397
- statements and <code>TODO</code> comments
398
- should be allowed. It adds the
399
- same globals as this directive:
400
- <blockquote><code>/*global </code>
401
- <div><code>alert, confirm, console, prompt</code></div>
402
- <code> */</code></blockquote>Be sure to turn this option off before going
403
- into production.</td>
404
- </tr>
405
- <tr>
406
- <td id="eval">Tolerate <code>eval</code></td>
407
- <td><code>eval</code></td>
408
- <td><code>true</code> if <code>eval</code> should be allowed. In the
409
- past, the <code>eval</code> function was the most misused
410
- feature of the language.</td>
411
- </tr>
412
- <tr>
413
- <td>Tolerate <code>for</code> statement</td>
414
- <td><code>for</code></td>
415
- <td><code>true</code> if the <code>for</code> statement should be
416
- allowed. It is almost always better to use the array methods
417
- instead.</td>
418
- </tr>
419
- <tr>
420
- <td id="getsest">Tolerate <code>get</code> and <code>set</code></td>
421
- <td><code>getset</code></td>
422
- <td><code>true</code> if accessor properties are allowed in object literals.</td>
423
- </tr>
424
- <tr>
425
- <td id="long">Tolerate long source lines</td>
426
- <td><code>long</code></td>
427
- <td><code>true</code> if a line can contain more than 80 characters.</td>
428
- </tr>
429
- <tr>
430
- <td id="name">Tolerate bad property names</td>
431
- <td><code>name</code></td>
432
- <td>
433
- <code>true</code> if bad property names like
434
- <code>$, _foo, fooSync, foo_</code>
435
- are allowed.
436
- </td>
437
- </tr>
438
- <tr>
439
- <td id="node">Assume <a href="https://nodejs.org/">Node.js</a></td>
440
- <td><code>node</code></td>
441
- <td><code>true</code> if Node.js globals should be predefined. It
442
- will predefine globals that are used in the Node.js environment.
443
- It adds the same globals as this directive:
444
- <blockquote><code>/*global </code>
445
- <div><code>
446
- Buffer, clearImmediate, clearInterval, clearTimeout,
447
- console, exports, module, process, require,
448
- setImmediate, setInterval, setTimeout, TextDecoder,
449
- TextEncoder, URL, URLSearchParams, __dirname, __filename
450
- </code></div>
451
- <code>*/</code></blockquote></td>
452
- </tr>
453
- <tr>
454
- <td id="single">Tolerate single quote strings</td>
455
- <td><code>single</code></td>
456
- <td><code>true</code> if <code>'</code><small>single quote</small>
457
- should be allowed to enclose string literals. </td>
458
- </tr>
459
- <tr>
460
- <td>Tolerate <code>this</code><br></td>
461
- <td><code>this</code></td>
462
- <td><code>true</code> if <code>this</code> should be allowed. </td>
463
- </tr>
464
- <tr>
465
- <td id="unordered">Tolerate unordered case-statements, params, properties.</td>
466
- <td><code>unordered</code></td>
467
- <td><code>true</code> if objects and functions are allowed to declare properties and params in non-alphabetical order.</td>
468
- </tr>
469
- <tr>
470
- <td id="white">Tolerate whitespace mess</td>
471
- <td><code>white</code></td>
472
- <td><code>true</code> if the whitespace rules should be ignored.</td>
473
- </tr>
474
- </tbody>
475
- </table>
476
- </center>
477
-
478
- <p>For example:</p>
479
- <pre>/*jslint
480
- bitwise, node
481
- */</pre>
482
-
483
- <h1 id=property><code>/*property*/</code></h1>
484
- <p>The <code>/*property*/</code> directive is used to declare a list of
485
- property identifiers that are used in the file. Each property name in the
486
- program is looked up in this list. If a name is not found, that indicates an
487
- error, most likely a typing error.</p>
488
- <p>The list can also be used to evade some of JSLint&rsquo;s naming
489
- rules.</p>
490
- <p>JSLint can build the <code>/*property*/</code> list for you. At
491
- the bottom of its report, JSLint displays a
492
- <code>/*property*/</code> directive. It contains all of the names that were
493
- used with dot notation, subscript notation, and object literals to name the
494
- properties of objects. You can look through the list for misspellings. You
495
- can copy the <code>/*property*/</code> directive to the top of your
496
- script file. JSLint will check the spelling of all property
497
- names against the list. That way, you can have JSLint look for
498
- misspellings for you.</p>
499
- <p>For example,</p>
500
- <blockquote><code>/*property
501
- <div>charAt, slice, _$_</div>
502
- */</code></blockquote>
503
- <h1 id=ignore><code>ignore</code></h1>
504
- <p>JSLint introduces a new reserved word: <code>ignore</code>. It
505
- is used in parameter lists and in <code>catch</code> clauses to indicate a
506
- parameter that will be ignored. Unused warnings will not be produced for
507
- <code>ignore</code>.
508
- <pre>function handler(ignore, value) {
509
- return do_something_useful(value);
510
- }</pre>
511
- <h1 id=var><code>var let const</code></h1>
512
- <p>JavaScript provides three statements for declaring variables:
513
- <code>var</code>, <code>let</code>, and <code>const</code>. The
514
- <code>var</code> statement suffers from a bad practice called hoisting. The
515
- <code>let</code> statement does not do hoisting and respects block scope.
516
- The <code>const</code> statement is like <code>let</code> except that it
517
- marks the variable (but not its contents) as read only, making it an error
518
- to attempt to assign to the variable. When given a choice,
519
- <code>const</code> is the best, <code>var</code> is the worst. </p>
520
- <p>JSLint uses the intersection of the <code>var</code> rules and the
521
- <code>let</code> rules, and by doing so avoids the errors related to either.
522
- A name should be declared only once in a function. It should be declared
523
- before it is used. It should not be used outside of the block in which it is
524
- declared. A variable should not have the same name as a variable or
525
- parameter in an outer function. Do not mix <code>var</code> and
526
- <code>let</code>. Declare one name per statement.</p>
527
- <h1 id=eq><code>= == ===</code></h1>
528
- <p><span style="asset_font_variant: small-caps;">Fortran</span> made a terrible
529
- mistake in using the equality operator as its assignment operator. That
530
- mistake has been replicated in most languages since then. C compounded that
531
- mistake by making <code>==</code> its equality operator. The visual
532
- similarity is a source of errors. JavaScript compounded this further by
533
- making <code>==</code> a type coercing comparison operator that produces
534
- false positive results. This was mitigated by adding the <code>===</code>
535
- operator, leaving the broken <code>==</code> operator in place.</p>
536
- <p>JSLint attempts to minimize errors by the following rules:</p>
537
- <p><code>==</code> is not allowed. This avoids the false positives, and
538
- increases the visual distance between <code>=</code> and <code>===</code>.
539
- Assignments are not allowed in expression position, and comparisons are not
540
- allowed in statement position. This also reduces confusion.&nbsp;</p>
541
- <h1 id=semicolon>Semicolon</h1>
542
- <p>JavaScript uses a C-like syntax that requires the use of semicolons to
543
- delimit certain statements. JavaScript attempts to make those semicolons
544
- optional with an automatic semicolon insertion mechanism, but it does not
545
- work very well. Automatic semicolon insertion was added to make
546
- things easier for beginners. Unfortunately, it sometimes fails. Do not rely
547
- on it unless you are a beginner.</p>
548
- <p>JSLint expects that every statement will be followed by
549
- <code>;</code> except for <code>for</code>, <code>function</code>,
550
- <code>if</code>, <code>switch</code>, <code>try</code>, and
551
- <code>while</code>. JSLint does not expect to see unnecessary
552
- semicolons, the empty statement, or empty blocks.</p>
553
- <h1 id=function><code>function =></code></h1>
554
- <p>JavaScript has four syntactic forms for making function objects: function
555
- statements, function expressions, enhanced object literals, and the
556
- <code>=&gt;</code>&nbsp;<small>fart</small> operator.</p>
557
- <p>The function statement creates a variable and assigns the function object to
558
- it. It should be used in a file or function body, but not inside of a block.</p>
559
- <blockquote> <code>function </code><var>name</var><code>(</code><var>parameters</var><code>) {</code>
560
- <div><var>statements</var></div>
561
- <code>}</code> </blockquote>
562
- <p>The function expression unfortunately looks like the function statement. It
563
- may appear anywhere that an expression may appear, but not in statement
564
- position and not in a loop. It produces a function object but does not
565
- create a variable in which to store it.</p>
566
- <blockquote> <code>function (</code><var>parameters</var><code>) {</code>
567
- <div><var>statements</var></div>
568
- <code>}</code> </blockquote>
569
- <p>The enhanced object literal provides an ES6 shorthand for creating a property
570
- whose value is a function, saving you from having to type
571
- <code>:</code>&nbsp;<small>colon</small> and <code>function</code>.</p>
572
- <blockquote> <code>{</code>
573
- <div><var>name</var><code>(</code><var>parameters</var><code>) {</code>
574
- <div><var>statements</var></div>
575
- <code>}</code></div>
576
- <code>}</code> </blockquote>
577
- <p>Finally, ES6 provides an even shorter form of function expression that leaves
578
- out the words <code>function</code> and <code>return</code>:</p>
579
- <blockquote> <code>(</code><var>parameters</var><code>) =>
580
- </code><var>expression</var> </blockquote>
581
- <p>JSLint requires the parens around the parameters, and forbids a
582
- <code>{</code>&nbsp;<small>left brace</small> after the
583
- <code>=></code>&nbsp;<small>fart</small> to avoid syntactic ambiguity.</p>
584
- <h1 id=comma>Comma</h1>
585
- <p>The <code>,</code>&nbsp;<small>comma</small> operator is unnecessary and can
586
- mask programming errors.</p>
587
- <p>JSLint expects to see the comma used as a separator, but not as
588
- an operator. It does not expect to see elided elements in array literals. A
589
- comma should not appear after the last element of an array literal or object
590
- literal.</p>
591
- <h1 id=blocks>Blocks</h1>
592
- <p>JSLint expects blocks with <code>function</code>,
593
- <code>if</code>, <code>switch</code>, <code>while</code>, <code>for</code>,
594
- <code>do</code>, and <code>try</code> statements and nowhere else.</p>
595
- <p>JSLint expects that <code>if</code>, <code>while</code>,
596
- <code>do</code> and <code>for</code> statements will be made with blocks
597
- <code>{</code>that is, with statements enclosed in braces<code>}</code>.</p>
598
- <p>JavaScript allows an <code>if</code> to be written like this:</p>
599
- <pre>if (<i>condition</i><code>)
600
- </code><i>statement</i>;</pre>
601
- <p>That form is known to contribute to mistakes in projects where many
602
- programmers are working on the same code. That is why JSLint
603
- expects the use of a block:</p>
604
- <pre>if (<i>condition</i>) {
605
- <i>statements</i>;
606
- }</pre>
607
- <p>Experience shows that this form is more resilient.</p>
608
- <h1 id=expression>Expression Statements</h1>
609
- <p>An expression statement is expected to be an assignment or a function/method
610
- call. All other expression statements are considered
611
- to be errors.</p>
612
- <h1 id=for><code>for</code></h1>
613
- <p>JSLint does not recommend use of the <code>for</code> statement.
614
- Use array methods like <code>forEach</code> instead. The <code>for</code>
615
- option will suppress some warnings. The forms of <code>for</code> that
616
- JSLint accepts are restricted, excluding the new ES6 forms.</p>
617
- <h1 id=forin><code>for</code> <code>in</code></h1>
618
- <p>JSLint does not recommend use of the <code>for</code>
619
- <code>in</code> statement. Use <code>Object.keys</code> instead.</p>
620
- <p>The <code>for</code> <code>in</code> statement allows for looping through
621
- the names of all of the properties of an object. Unfortunately, it also
622
- loops through all of the properties that were inherited through the
623
- prototype chain. This has the bad side effect of serving up method
624
- functions when the interest is in data properties. If a program is written
625
- without awareness of this situation, then it can fail.</p>
626
- <p>The body of every <code>for</code> <code>in</code> statement should be
627
- wrapped in an <code>if</code> statement that does filtering. It can select
628
- for a particular type or range of values, or it can exclude functions,
629
- or it can exclude properties from the prototype. For example,</p>
630
- <pre>for (name in object) {
631
- if (object.hasOwnProperty(name)) {
632
- ....
633
- }
634
- }</pre>
635
- <p>Note that the above code will fail if the object contains a property
636
- named <code>hasOwnProperty</code>. Use <code>Object.keys</code> instead.</p>
637
- <h1 id=switch><code>switch</code></h1>
638
- <p>A common error in <code>switch</code> statements is to forget to place a
639
- <code>break</code> statement after each case, resulting in unintended
640
- fall-through. JSLint expects that the statement before the next
641
- <code>case</code> or <code>default</code> is one of these:
642
- <code>break</code>, <code>return</code>, or <code>throw</code>.</p>
643
- <h1 id=with><code>with</code></h1>
644
- <p>The <code>with</code> statement was intended to provide a shorthand in
645
- accessing properties in deeply nested objects. Unfortunately, it behaves
646
- very badly when setting new properties. Never use the <code>with</code>
647
- statement.</p>
648
- <p>JSLint does not expect to see a <code>with</code> statement.</p>
649
- <h1 id=labels>Labels</h1>
650
- <p>JavaScript allows any statement to have a label, and labels have a
651
- separate name space. JSLint is more strict.</p>
652
- <p>JSLint expects labels only on statements that interact
653
- with <code>break</code>: <code>switch</code>, <code>while</code>,
654
- <code>do</code>, and <code>for</code>. JSLint expects that
655
- labels will be distinct from vars and parameters.</p>
656
- <h1 id=unreachable>Unreachable Code</h1>
657
- <p>JSLint expects that a <code>return</code>, <code>break</code>,
658
- or <code>throw</code> statement will be followed by a
659
- <code>}</code>&nbsp;<small>right brace</small> or <code>case</code> or
660
- <code>default</code>.</p>
661
- <h1 id=pluses>Confusing Pluses and Minuses</h1>
662
- <p>JSLint expects that <code>+</code> will not be followed by
663
- <code>+</code> or <code>++</code>, and that <code>-</code> will not be
664
- followed by <code>-</code> or <code>--</code>. A misplaced space can turn
665
- <code>+ +</code> into <code>++</code>, an error that is difficult to see.
666
- Use parens to avoid confusion.</p>
667
- <h1 id=inc><code>++</code> and <code>--</code></h1>
668
- <p>The <code>++</code>&nbsp;<small>increment</small> and
669
- <code>--</code>&nbsp;<small>decrement</small> operators have been known to
670
- contribute to bad code by encouraging excessive trickiness. They are second
671
- only to faulty architecture in enabling to viruses and other security
672
- menaces. Also, preincrement/postincrement confusion can produce off-by-one
673
- errors that are extremely difficult to diagnose. Fortunately, they are also
674
- complete unnecessary. There are better ways to add 1 to a variable.</p>
675
- <p>It is best to avoid these operators entirely and rely on <code>+=</code> and
676
- <code>-=</code> instead.</p>
677
- <h1 id=void><code>void</code></h1>
678
- <p>In most C-like languages, <code>void</code> is a type. In
679
- JavaScript, <code>void</code> is a prefix operator that always
680
- returns <code>undefined</code>. JSLint does not expect to
681
- see <code>void</code> because it is confusing and not very useful.</p>
682
- <h1 id=regexp>Regular Expressions</h1>
683
- <p>Regular expressions are written in a terse and cryptic notation.
684
- JSLint looks for problems that may cause portability problems.
685
- It also attempts to resolve visual ambiguities by recommending explicit
686
- escapement.</p>
687
- <p>JavaScript&rsquo;s syntax for regular expression literals overloads the
688
- <code>/</code>&nbsp;<small>slash</small> character. To avoid ambiguity,
689
- JSLint expects that the character preceding a regular
690
- expression literal is a <code>(</code>&nbsp;<small>left paren</small> or
691
- <code>=</code>&nbsp;<small>equal</small> or
692
- <code>:</code>&nbsp;<small>colon</small> or
693
- <code>,</code>&nbsp;<small>comma</small> character.</p>
694
- <h1 id=this><code>this</code></h1>
695
- <blockquote>Having <code>this</code> in the language makes it harder to talk
696
- about the language. It is like pair programming with Abbott and Costello.
697
- </blockquote>
698
- <p>Avoid using <code>this</code>. Warnings about <code>this</code> can be
699
- suppressed with <code>option.this</code>.</p>
700
- <h1 id=new>Constructors and <code>new</code></h1>
701
- <p>Constructors are functions that are designed to be used with the
702
- <code>new</code> prefix. The <code>new</code> prefix creates a new object
703
- based on the function's <code>prototype</code>, and binds that object to the
704
- function's implied <code>this</code> parameter. If you neglect to use the
705
- <code>new</code> prefix, no new object will be made and <code>this</code>
706
- will be bound to the global object.</p>
707
- <p>JSLint enforces the convention that constructor functions be
708
- given names with initial uppercase. JSLint does not expect to
709
- see a function invocation with an initial uppercase name unless it has the
710
- <code>new</code> prefix. JSLint does not expect to see the
711
- <code>new</code> prefix used with functions whose names do not start with
712
- initial uppercase.</p>
713
- <p>JSLint does not expect to see the wrapper forms
714
- <code>new Number</code>, <code>new String</code>, <code>new Boolean</code>.</p>
715
- <p>JSLint does not expect to see <code>new Object</code>.
716
- Use <code>Object.create(null)</code> instead.</p>
717
- <h1>Whitespace</h1>
718
- <p>JSLint has a specific set of rules about the use of whitespace.
719
- Where possible, these rules are consistent with centuries of good practice
720
- with literary style.</p>
721
- <p>The indentation increases by 4 spaces when the last token on a line is
722
- <code>{</code>&nbsp;<small>left brace</small>,
723
- <code>[</code>&nbsp;<small>left bracket</small>,
724
- <code>(</code>&nbsp;<small>left paren</small>. The matching closing
725
- token will be the first token on a line, restoring the previous
726
- indentation.</p>
727
- <p>The ternary operator can be visually confusing, so
728
- <code>?</code>&nbsp;<small>question mark</small> and
729
- <code>:</code>&nbsp;<small>colon</small> always begin a line and increase
730
- the indentation by 4 spaces.</p>
731
- <pre>return (
732
- (the_token.id === "(string)" || the_token.id === "(number)")
733
- ? String(the_token.value)
734
- : the_token.id
735
- );</pre>
736
- <p>The word <code>function</code> is always followed with one space.</p>
737
- <p>Clauses (<code>case</code>, <code>catch</code>, <code>default</code>,
738
- <code>else</code>, <code>finally</code>) are not statements and so should
739
- not be indented like statements.</p>
740
- <p>Spaces are used to make things that are not invocations look less like
741
- invocations.</p>
742
- <p>Tabs and spaces should not be mixed. We should pick just one in order to
743
- avoid the problems that come from having both. Personal preference is an
744
- extremely unreliable criterion. Neither offers a powerful advantage over the
745
- other. Fifty years ago, tab had the advantage of consuming less memory, but
746
- Moore's Law has eliminated that advantage. Space has one clear advantage
747
- over tab: there is no reliable standard for how many spaces a tab
748
- represents, but it is universally accepted that a space occupies a space. So
749
- use spaces. You can edit with tabs if you must, but make sure it is spaces
750
- again before you commit. Maybe someday we will finally get a universal
751
- standard for tabs, but until that day comes, the better choice is spaces.</p>
752
- <h1 id=report>Report</h1>
753
- <p>If JSLint is able to complete its scan, it generates a function
754
- report. It lists for each function:</p>
755
- <ul>
756
- <li>The line number on which it starts.</li>
757
- <li>The function&rsquo;s name. In the case of anonymous functions,
758
- JSLint will attempt to
759
- <code>«</code>guess<code>»</code> the name.</li>
760
- <li>The parameters.</li>
761
- <li><i>Variables</i>: The variables that are declared in the function.</li>
762
- <li><i>Closure</i>: The variables and parameters that are declared in
763
- the function that are used by its inner functions.</li>
764
- <li><i>Exceptions</i>: The variables that are declared by <code>catch</code>
765
- clauses of <code>try</code> statements.</li>
766
- <li><i>Outer</i>: Variables used by this function that are declared in
767
- other functions.</li>
768
- <li><i>Global</i>: Global variables that are used by this function. Keep
769
- these to a minimum.</li>
770
- <li><i>Label</i>: Statement labels that are used by this function.</li>
771
- </ul>
772
- <p>The report will also include a list of all of the property
773
- names that were used.</p>
774
- <h1 id=feedback>Feedback</h1>
775
- <p>Please let me know if JSLint is useful for you. Is it too
776
- strict? Is there a check or a report that could help you to improve the
777
- quality of your programs?
778
- <a href="mailto:douglas@crockford.com">douglas@crockford.com</a>.
779
- But please don't ask me to dumb JSLint down or to make it more
780
- forgiving of bad practices. You would only be disappointed.</p>
781
- <p>I intend to continue to adapt JSLint based on your comments.
782
- Keep watching for improvements.</p>
783
- <h1 id=try>Try it</h1>
784
- <p><a href="https://www.jslint.com/">Try it.</a> Paste your script
785
- into the window and click the
786
- <a href="https://www.jslint.com/"><button>JSLint</button></a>
787
- button. The analysis is done by a script running on your machine.
788
- Your script is not sent over the network. You can set the options used.</p>
789
- <p>JSLint is written entirely in JavaScript, so it can run
790
- anywhere that JavaScript (or even Java) can run.</p>
791
- <h1>Perfectly fine</h1>
792
- <p>JSLint was designed to reject code that some would consider to
793
- be <b>perfectly fine</b>. The reason for this is that JSLint's
794
- purpose is to help produce programs that are free of error. That is
795
- difficult in any language and is especially hard in JavaScript.
796
- JSLint attempts to help you increase the visual distance
797
- between correct programs and incorrect programs, making the remaining errors
798
- more obvious. JSLint will give warnings about things that are
799
- not necessarily wrong in the current situation, but which have been observed
800
- to mask or obscure errors. Avoid those things when there are better options
801
- available. </p>
802
- <p>It is dangerous out there. JSLint is here to help.</p>
803
- <h1 id=warning>Warning</h1>
804
- <p>JSLint will hurt your feelings. Side effects may include
805
- headache, irritability, dizziness, snarkiness, stomach pain, defensiveness,
806
- dry mouth, cleaner code, and a reduced error rate.</p>
807
-
808
- <h1 id=jslint>JSLint</h1>
809
- <p>JSLint is delivered as a set of files:</p>
810
- <center><table align="center">
811
- <tr><th>Filename</th><th>Content</th></tr>
812
- <tr><td><code>help.html</code></td>
813
- <td>Using <code>jslint</code> as a single page JSLint application.</td></tr>
814
- <tr><td><code>index.html</code></td>
815
- <td>Single page JSLint application that uses the
816
- <code>js</code> files.</td></tr>
817
- <tr><td><code>jslint.mjs</code></td>
818
- <td>The <code>jslint</code> function.</td></tr>
819
- </table></center>
820
- <h1><code>function jslint</code></h1>
821
- <p>The <code>jslint</code> function is written in ES6 JavaScript. It has no
822
- dependence on other files.</p>
823
- <p>The <code>jslint</code> function has three arguments:</p>
824
- <center><table>
825
- <tr>
826
- <th>Parameter name</th>
827
- <th>Type</th>
828
- <th>Volition</th><th>Description</th></tr>
829
- <tr><td><code>source</code></td><td><code>string</code> or
830
- <code>array</code></td><td>required</td><td>This is the source of the
831
- program to be analyzed. It can be either a string containing
832
- <code>\n</code>, <code>\r</code>, or <code>\r\n</code> line breaks, or an
833
- array of strings, one element per line.</td></tr>
834
- <tr><td><code>option_object</code></td><td><code>object</code></td>
835
- <td>optional</td><td>This object contains the chosen options for this
836
- analysis. The keys are the names of the options described on the
837
- <a href="help.html">help page</a>. The values are either the boolean
838
- <code>true</code> or a small number.</td></tr>
839
- <tr><td><code>global_array</code></td><td><code>array</code></td><td>optional</td>
840
- <td>This is an array of strings. Each string names one global variable that
841
- may be used by the program. Listing names here will silence warnings
842
- about the names. It will not introduce the names into the runtime
843
- environment.</td></tr>
844
- </table></center>
845
- <p>The <code>jslint</code> function will not modify any of its arguments.</p>
846
- <p>The <code>jslint</code> function will return a result object contain the
847
- following properties:</p>
848
- <center><table>
849
- <tr>
850
- <th>Property name</th>
851
- <th>Type</th>
852
- <th>Content</th></tr>
853
- <tr>
854
- <td><code>directives</code></td>
855
- <td>array</td>
856
- <td>An array of comments containing directives.</td></tr>
857
- <tr><td><code>edition</code></td><td>string</td>
858
- <td>The verison of <code>jslint</code> that produced the result.</td></tr>
859
- <tr><td><code>exports</code></td><td>object</td>
860
- <td>All of the exported names and values.</td></tr>
861
- <tr><td><code>froms</code></td><td>array</td>
862
- <td>All of the strings named in <code>import</code> statements.</td></tr>
863
- <tr><td><code>functions</code></td><td>array</td>
864
- <td>An array of function objects.</td></tr>
865
- <tr><td><code>global</code></td><td>object</td>
866
- <td>The global object, a body that contains the outermost statements and
867
- variables.</td></tr>
868
- <tr><td><code>id</code></td><td>string</td>
869
- <td><code>"(JSLint)"</code></td></tr>
870
- <tr><td><code>json</code></td><td>boolean</td>
871
- <td><code>true</code> if the source was a
872
- <a href="https://www.json.org/">JSON</a> text.</td></tr>
873
- <tr><td><code>lines</code></td><td>array</td>
874
- <td>An array of strings, one for each line of text in the source.</td></tr>
875
- <tr><td><code>module</code></td><td>boolean</td>
876
- <td><code>true</code> if the file contains an <code>import</code> or
877
- <code>export</code>.</td></tr>
878
- <tr><td><code>ok</code></td><td>boolean</td>
879
- <td><code>true</code> if no warnings were found.</td></tr>
880
- <tr><td><code>option</code></td><td>object</td>
881
- <td>The option object that was passed in, or an empty substitute.</td></tr>
882
- <tr><td><code>property</code></td><td>object</td>
883
- <td>The names are the names of properties used in the source. The values are
884
- the number of times each name occurred.</td></tr>
885
- <tr><td><code>stop</code></td><td>boolean</td>
886
- <td><code>true</code> if JSLint was not able to process the
887
- entire file.</td></tr>
888
- <tr><td><code>tokens</code></td><td>array</td>
889
- <td>All of the token objects in source order.</td></tr>
890
- <tr><td><code>tree</code></td><td>array</td>
891
- <td>The token objects that represent the outermost statements. Those will be
892
- linked to other tokens, forming an abstract parse tree.</td></tr>
893
- <tr><td><code>warnings</code></td><td>array</td>
894
- <td>The warning objects.</td></tr>
895
- </table>
896
- <h1>Tokens</h1>
897
- <p>A source file is composed of tokens. Each identifier, each operator, each
898
- punctuator, each literal, and each comment is a token. The whitespace
899
- between tokens is not a token.</p>
900
- <p>An object is made for each token. The properties in each token will vary
901
- according to the type of the token. More properties will be added to the
902
- tokens during the analysis to indicate the token's purpose or
903
- relationship with other tokens. The tokens will be woven together to
904
- form a tree. </p>
905
- <table>
906
- <tr>
907
- <th scope="col">Property name</th>
908
- <th scope="col">Type</th>
909
- <th scope="col">Description</th>
910
- <th scope="col">Where</th>
911
- </tr>
912
- <tr>
913
- <td><code>arity</code></td>
914
- <td>string</td>
915
- <td><code>unary</code>, <code>binary</code>, <code>ternary</code>,
916
- <code>assignment</code>, <code>statement</code>,
917
- <code>variable</code>, <code>function</code>, <code>pre</code>,
918
- <code>post</code></td>
919
- <td>non-literals</td>
920
- </tr>
921
- <tr>
922
- <td><code>block</code></td>
923
- <td>token or array of tokens</td>
924
- <td>This is the contents of a block or compound statement. Each
925
- token represents a statement.</td>
926
- <td>statement</td>
927
- </tr>
928
- <tr>
929
- <td><code>body</code></td>
930
- <td>boolean</td>
931
- <td><code>true</code> if the block is a function body.</td>
932
- <td>block</td>
933
- </tr>
934
- <tr>
935
- <td><code>catch</code></td>
936
- <td>token</td>
937
- <td>The <code>catch</code> clause.</td>
938
- <td>try</td>
939
- </tr>
940
- <tr>
941
- <td><code>closure</code></td>
942
- <td>boolean</td>
943
- <td><code>true</code> if accessed by inner functions</td>
944
- <td>variable</td>
945
- </tr>
946
- <tr>
947
- <td><code>complex</code></td>
948
- <td>boolean</td>
949
- <td><code>true</code> if one or more parameters use new ES6 syntax</td>
950
- <td>function</td>
951
- </tr>
952
- <tr>
953
- <td><code>constant</code></td>
954
- <td>boolean</td>
955
- <td><code>true</code> if the thing is a compile-time constant</td>
956
- <td>token</td>
957
- </tr>
958
- <tr>
959
- <td><code>context</code></td>
960
- <td>object</td>
961
- <td>The container of variables, parameters, labels, and exception
962
- variables declared in a function.</td>
963
- <td>function</td>
964
- </tr>
965
- <tr>
966
- <td><code>directive</code></td>
967
- <td>boolean</td>
968
- <td><code>jslint</code>, <code>global</code>, <code>property</code></td>
969
- <td>comment</td>
970
- </tr>
971
- <tr>
972
- <td><code>disrupt</code></td>
973
- <td>boolean</td>
974
- <td><code>true</code> if a disruptive statement, or a block ending
975
- with a distruption. An <code>if</code> will disrupt if both of
976
- its branches disrupt.</td>
977
- <td>statement</td>
978
- </tr>
979
- <tr>
980
- <td><code>dot</code></td>
981
- <td>boolean</td>
982
- <td><code>true</code> if the previous token was a dot.</td>
983
- <td>identifier</td>
984
- </tr>
985
- <tr>
986
- <td><code>ellipsis</code></td>
987
- <td>boolean</td>
988
- <td><code>true</code> if the parameter or argument is preceded by
989
- the ellipsis.</td>
990
- <td>token</td>
991
- </tr>
992
- <tr>
993
- <td><code>else</code></td>
994
- <td>array of tokens</td>
995
- <td>Alternate block in
996
- <code>if</code> (<code>else</code>),
997
- <code>switch</code> (<code>default</code>),
998
- <code>try</code> (<code>finally</code>)</td>
999
- <td>statement</td>
1000
- </tr>
1001
- <tr>
1002
- <td><code>expression</code></td>
1003
- <td>token or array of tokens</td>
1004
- <td>One or more expressions.</td>
1005
- <td>operator or statement</td>
1006
- </tr>
1007
- <tr>
1008
- <td><code>extra</code></td>
1009
- <td>string</td>
1010
- <td><code>get</code>, <code>set</code></td>
1011
- <td>properties</td>
1012
- </tr>
1013
- <tr>
1014
- <td><code>flag</code></td>
1015
- <td>object</td>
1016
- <td>An object containing the properties <code>g</code>,
1017
- <code>i</code>, <code>m</code>, <code>u</code>, or
1018
- <code>y</code>.</td>
1019
- <td>regexp</td>
1020
- </tr>
1021
- <tr>
1022
- <td><code>from</code></td>
1023
- <td>number</td>
1024
- <td>The starting position of the token within its line of source
1025
- code. A token at the extreme left margin has a <code>from</code>
1026
- of 0.</td>
1027
- <td>token</td>
1028
- </tr>
1029
- <tr>
1030
- <td><code>parent</code></td>
1031
- <td>token</td>
1032
- <td>The function in which the variable was declared.</td>
1033
- <td>variable</td>
1034
- </tr>
1035
- <tr>
1036
- <td><code>id</code></td>
1037
- <td>string</td>
1038
- <td>The <code>id</code> of the token. For most tokens, this is the
1039
- token text itself. <br>
1040
- For comments, <code>id</code> is <code>"(comment)"</code>.<br>For
1041
- number literals, <code>id</code> is <code>"(number)"</code>. <br>
1042
- For regular expression literals, <code>id</code> is
1043
- <code>"(regexp)"</code>.<br>For string literals, <code>id</code> is
1044
- <code>"(string)"</code>.<br>
1045
- The end of the file has an <code>id</code> of <code>"(end)"</code>.<br>
1046
- The global object has an <code>id</code> of <code>"(global)"</code>.</td>
1047
- <td>token</td>
1048
- </tr>
1049
- <tr>
1050
- <td><code>identifier</code></td>
1051
- <td>boolean</td>
1052
- <td><code>true</code> if the token is an identifier.</td>
1053
- <td>token</td>
1054
- </tr>
1055
- <tr>
1056
- <td><code>import</code></td>
1057
- <td>string</td>
1058
- <td>The <code>import</code> <code>from</code> string literal.</td>
1059
- <td>import</td>
1060
- </tr>
1061
- <tr>
1062
- <td><code>inc</code></td>
1063
- <td>token</td>
1064
- <td>The increment clause of a <code>for</code> statement.</td>
1065
- <td>for</td>
1066
- </tr>
1067
- <tr>
1068
- <td><code>initial</code></td>
1069
- <td>token</td>
1070
- <td>The initialization clause of a <code>for</code> statement.</td>
1071
- <td>for</td>
1072
- </tr>
1073
- <tr>
1074
- <td><code>label</code></td>
1075
- <td>token</td>
1076
- <td>The label of a statement, or the name of a property in an object
1077
- literal.</td>
1078
- <td>statement or object literal</td>
1079
- </tr>
1080
- <tr>
1081
- <td><code>level</code></td>
1082
- <td>number</td>
1083
- <td>The function nesting level. The global context is 0. The
1084
- outermost functions are 1. Their inner functions are 2.</td>
1085
- <td>function</td>
1086
- </tr>
1087
- <tr>
1088
- <td><code>line</code></td>
1089
- <td>number</td>
1090
- <td>The line number on which the token was found. A token on the
1091
- first line will have a <code>line</code> of 0. If the token
1092
- spans multiple lines (such as a long comment) <code>line</code>
1093
- will be the number of the last line it occupied. </td>
1094
- <td>token</td>
1095
- </tr>
1096
- <tr>
1097
- <td><code>name</code></td>
1098
- <td>token or string</td>
1099
- <td>The name of a function</td>
1100
- <td>function</td>
1101
- </tr>
1102
- <tr>
1103
- <td><code>names</code></td>
1104
- <td>token or array of tokens</td>
1105
- <td>Parameters or variables on the left of <code>=</code>.</td>
1106
- <td><code>=</code> or <code>(</code></td>
1107
- </tr>
1108
- <tr>
1109
- <td><code>nr</code></td>
1110
- <td>number</td>
1111
- <td>The token sequence number.</td>
1112
- <td>token</td>
1113
- </tr>
1114
- <tr>
1115
- <td><code>parameters</code></td>
1116
- <td>array of tokens</td>
1117
- <td>The parameter list.</td>
1118
- <td>function</td>
1119
- </tr>
1120
- <tr>
1121
- <td><code>parent</code></td>
1122
- <td>token</td>
1123
- <td>The function in which the variable was declared.</td>
1124
- <td>variable</td>
1125
- </tr>
1126
- <tr>
1127
- <td><code>quote</code></td>
1128
- <td>string</td>
1129
- <td>The quote character.</td>
1130
- <td>string literal</td>
1131
- </tr>
1132
- <tr>
1133
- <td><code>role</code></td>
1134
- <td>string</td>
1135
- <td><code>exception</code>, <code>function</code>,
1136
- <code>label</code>, <code>parameter</code>, <code>variable</code></td>
1137
- <td>identifier</td>
1138
- </tr>
1139
- <tr>
1140
- <td><code>shebang</code></td>
1141
- <td>string</td>
1142
- <td>The first line of text if it started with <code>#!</code></td>
1143
- <td>line</td>
1144
- </tr>
1145
- <tr>
1146
- <td><code>statement</code></td>
1147
- <td>boolean</td>
1148
- <td><code>true</code> if the token is the first token of a statement.</td>
1149
- <td>statement</td>
1150
- </tr>
1151
- <tr>
1152
- <td><code>strict</code></td>
1153
- <td>token</td>
1154
- <td>The <code>"use strict"</code> pragma.</td>
1155
- <td>block</td>
1156
- </tr>
1157
- <tr>
1158
- <td><code>thru</code></td>
1159
- <td>number</td>
1160
- <td>The ending position of the token within its line of source code.
1161
- It is usually <code>from</code> plus the length of the token.</td>
1162
- <td>token</td>
1163
- </tr>
1164
- <tr>
1165
- <td><code>value</code></td>
1166
- <td>string or array of strings</td>
1167
- <td>The text of the token. For a long comment or megastring, this
1168
- could be an array of strings.</td>
1169
- <td>literals</td>
1170
- </tr>
1171
- <tr>
1172
- <td><code>variable</code></td>
1173
- <td>token</td>
1174
- <td>This links a variable to its definition.</td>
1175
- <td>variable</td>
1176
- </tr>
1177
- <tr>
1178
- <td><code>warning</code></td>
1179
- <td>object</td>
1180
- <td>A warning object triggered by this token.</td>
1181
- <td>token</td>
1182
- </tr>
1183
- <tr>
1184
- <td><code>wrapped</code></td>
1185
- <td>boolean</td>
1186
- <td><code>true</code> if the expression was wrapped in parens.</td>
1187
- <td>expression</td>
1188
- </tr>
1189
- <tr>
1190
- <td><code>writable</code></td>
1191
- <td>boolean</td>
1192
- <td><code>true</code> if the variable may be assigned to.</td>
1193
- <td>variable</td>
1194
- </tr>
1195
- </table>
1196
- <h1>Reports</h1>
1197
- <p>The <code>report</code> object contains three functions that all take a
1198
- result from the <code>jslint</code> function as input.
1199
- <table>
1200
- <tr>
1201
- <th scope="col">Function name</th>
1202
- <th scope="col">Description</th>
1203
- </tr>
1204
- <tr>
1205
- <td><code>error</code></td>
1206
- <td>This function takes a result and returns an HTML text fragment
1207
- from the warnings that are found.</td>
1208
- </tr>
1209
- <tr>
1210
- <td><code>function</code></td>
1211
- <td>This function takes a result and returns an HTML text fragment
1212
- detailing the declarations of every function.</td>
1213
- </tr>
1214
- <tr>
1215
- <td><code>property</code></td>
1216
- <td>This function takes a result and returns a JSLint
1217
- property directive. This directive could be pasted into a file.</td>
1218
- </tr>
1219
- </table>
1220
- <p>&nbsp;</p>
1221
- </center>
1222
-
1223
- <h1 id=reading>Further Reading</h1>
1224
- <center>
1225
- <p><a href="https://www.crockford.com/javascript/code.html">
1226
- Code Conventions for the JavaScript Programming Language.</a></p>
1227
- <a href="https://www.jslint.com/"><img src="asset_image_logo_512.svg" height="20"></a>
1228
- <a href="https://github.com/jslint-org/jslint"><img src="asset_image_github_brands.svg" height="20"></a>
1229
- <a href="https://www.json.org/"><img src="asset_image_json_160.svg" height="20"></a>
1230
- </center>
1231
- </body>
1232
- </html>