OSDN Git Service

Regular updates
[twpd/master.git] / jshint.md
1 ---
2 title: Jshint
3 category: JavaScript libraries
4 layout: 2017/sheet
5 updated: 2017-09-12
6 ---
7
8 ### Relaxing
9
10 Enable these options to *not* throw errors in these conditions.
11 See: [Relaxing](http://www.jshint.com/docs/options/#relaxing-options)
12 {: .-setup}
13
14 ```js
15 /* jshint asi: true */
16 allow()
17 missing_semicolons()
18 ```
19
20 ```js
21 /* jshint boss: true */
22 if (m = str.match(/.../))
23 ```
24
25 ```js
26 /* jshint debug: true */
27 debugger;
28 ```
29
30 ```js
31 /* jshint eqnull: true */
32 if (x == null)
33 ```
34
35 ```js
36 /* jshint evil: true */
37 eval('...')
38 ```
39
40 ```js
41 /* jshint expr: true */
42 production && minify = true;
43 div.innerWidth;
44 expect(x).be.true;
45 ```
46
47 ```js
48 /* jshint laxcomma: true */
49 var one = 1
50   , two = 2;
51 ```
52
53 ```js
54 /* jshint loopfunc: true */
55 for (i=0; i<10; x++) {
56   (function(i) { ... })(i);
57 }
58 ```
59
60 ```js
61 /* jshint sub: true */
62 process.env['name_here']
63 ```
64
65 ```js
66 /* jshint strict: "global" */
67 "use strict";
68 ```
69
70 ### Enforcing
71
72 Enable these options to catch more errors.
73 See: [Enforcing](http://www.jshint.com/docs/options/#enforcing-options)
74 {: .-setup}
75
76 ```js
77 /* jshint curly: true */
78 while (day)                     // err: use { }'s
79   shuffle();
80 ```
81
82 ```js
83 /* jshint eqeqeq: true */
84 if (a == null)                  // err: use ===
85 ```
86
87 ```js
88 /* jshint es3: true */
89 // ...for legacy IE compatibility
90 a.default = function() { ... }; // err: reserved word
91 array = [ 1, 2, 3, ];           // err: extra comma
92 ```
93
94 ```js
95 /* jshint forin: true */
96 for (key in obj) { ... }        // err: check obj.hasOwnProperty(key)
97 ```
98
99 ```js
100 /* jshint freeze: true */
101 Array.prototype.count = ...;    // err: don't modify native prototypes
102 ```
103
104 ```js
105 /* jshint indent: 4 */
106 if (x) {                        // err: expected indent of 4, found 2
107   ...;
108 }
109 ```
110
111 ```js
112 /* jshint quotmark: single */
113 /* jshint quotmark: double */
114 alert("hi");                    // err: only single allowed
115 ```
116
117 ```js
118 /* jshint strict: true */
119 function() { ... }              // err: need "use strict"
120 ```
121
122 ```js
123 /* jshint white: true, indent: 4 */
124 /* jshint maxdepth: 2 */
125 /* jshint maxparams: 3 */
126 /* jshint maxstatements: 4 */
127 /* jshint maxcomplexity: 5 */
128 /* jshint maxlen: 80 */
129 ```
130
131 ### Ignore
132
133 ```js
134 /* jshint ignore:start */
135 /* jshint ignore:end */
136 ```
137
138 ### Globals and Environments
139
140 ```js
141 /* jshint undef: true */
142 /* global jQuery */
143 /* global -BAD_LIB */
144 ```
145
146 ```js
147 /* jshint devel: true */   console, alert, ...
148 /* jshint browser: true */ window, document, location, ...
149 /* jshint node: true */    module, exports, console, process, ...
150 /* jshint jquery: true */  jQuery, $
151 ```
152
153 See: [Environments](http://www.jshint.com/docs/options/#environments)
154
155 ### Also see
156
157 * <http://www.jshint.com/docs/options/>
158 * <https://gist.github.com/haschek/2595796>