0
# Configuration Options
1
2
Comprehensive configuration system with enforcing, relaxing, and environment options for customizing JSHint's linting behavior. JSHint provides fine-grained control over which warnings and errors to report.
3
4
## Capabilities
5
6
### Configuration Structure
7
8
JSHint configuration is organized into three main categories of boolean options plus value-based options.
9
10
```javascript { .api }
11
// JSHint Configuration Options Object
12
{
13
// Enforcing options (stricter checking)
14
bitwise: boolean, // Prohibit bitwise operators
15
camelcase: boolean, // Force camelCase (deprecated)
16
curly: boolean, // Require curly braces
17
eqeqeq: boolean, // Prohibit == and !=
18
es3: boolean, // ES3 compliance (deprecated)
19
es5: boolean, // ES5 compliance (deprecated)
20
forin: boolean, // Require hasOwnProperty in for-in loops
21
freeze: boolean, // Prohibit native object extension
22
futurehostile: boolean, // Warn about future reserved words
23
immed: boolean, // Require immediate function invocation wrapping
24
latedef: boolean, // Prohibit use before definition
25
newcap: boolean, // Require constructor names capitalization
26
noarg: boolean, // Prohibit arguments.caller/callee
27
noempty: boolean, // Prohibit empty blocks
28
nonew: boolean, // Prohibit constructor usage for side effects
29
plusplus: boolean, // Prohibit ++ and --
30
quotmark: boolean, // Enforce quote marks
31
undef: boolean, // Require variable declarations
32
unused: boolean, // Warn about unused variables
33
strict: boolean, // Require strict mode
34
varstmt: boolean, // Disallow var statements
35
regexpu: boolean, // Enable RegExp u flag support
36
37
// Relaxing options (more permissive)
38
asi?: boolean;
39
boss?: boolean;
40
debug?: boolean;
41
eqnull?: boolean;
42
elision?: boolean;
43
esnext?: boolean;
44
evil?: boolean;
45
expr?: boolean;
46
funcscope?: boolean;
47
globalstrict?: boolean;
48
iterator?: boolean;
49
lastsemic?: boolean;
50
laxbreak?: boolean;
51
laxcomma?: boolean;
52
loopfunc?: boolean;
53
multistr?: boolean;
54
moz?: boolean;
55
notypeof?: boolean;
56
noyield?: boolean;
57
plusplus?: boolean;
58
proto?: boolean;
59
scripturl?: boolean;
60
sub?: boolean;
61
supernew?: boolean;
62
validthis?: boolean;
63
withstmt?: boolean;
64
65
// Environment options
66
browser?: boolean;
67
couch?: boolean;
68
devel?: boolean;
69
dojo?: boolean;
70
jasmine?: boolean;
71
jquery?: boolean;
72
mocha?: boolean;
73
module?: boolean;
74
mootools?: boolean;
75
node?: boolean;
76
nonstandard?: boolean;
77
phantom?: boolean;
78
prototypejs?: boolean;
79
qunit?: boolean;
80
rhino?: boolean;
81
shelljs?: boolean;
82
typed?: boolean;
83
worker?: boolean;
84
wsh?: boolean;
85
yui?: boolean;
86
87
// Value-based options
88
esversion?: number;
89
maxlen?: number;
90
maxerr?: number;
91
maxdepth?: number;
92
maxstatements?: number;
93
maxcomplexity?: number;
94
maxparams?: number;
95
indent?: number;
96
quotmark?: boolean | 'single' | 'double';
97
shadow?: boolean | 'inner' | 'outer';
98
strict?: boolean | 'global' | 'implied';
99
unused?: boolean | 'vars' | 'strict';
100
latedef?: boolean | 'nofunc';
101
ignore?: string;
102
ignoreDelimiters?: string;
103
predef?: string[] | {[key: string]: boolean};
104
globals?: {[key: string]: boolean};
105
scope?: string;
106
}
107
```
108
109
### Enforcing Options
110
111
Stricter checking options that enable additional warnings and enforce best practices.
112
113
```javascript { .api }
114
interface EnforcingOptions {
115
/**
116
* Prohibits bitwise operators (&, |, ^, etc.)
117
* Prevents common typos like & instead of &&
118
*/
119
bitwise: boolean;
120
121
/**
122
* Enforces camelCase naming convention for variables
123
*/
124
camelcase: boolean;
125
126
/**
127
* Requires curly braces around blocks in if/for/while statements
128
*/
129
curly: boolean;
130
131
/**
132
* Requires === and !== instead of == and !=
133
*/
134
eqeqeq: boolean;
135
136
/**
137
* Enforces ECMAScript 3 compatibility
138
*/
139
es3: boolean;
140
141
/**
142
* Enforces ECMAScript 5.1 compatibility
143
*/
144
es5: boolean;
145
146
/**
147
* Requires hasOwnProperty checks in for-in loops
148
*/
149
forin: boolean;
150
151
/**
152
* Prohibits overwriting native objects like Array, Date
153
*/
154
freeze: boolean;
155
156
/**
157
* Warns about identifiers defined in future ECMAScript versions
158
*/
159
futurehostile: boolean;
160
161
/**
162
* Requires immediate function invocations to be wrapped in parentheses
163
*/
164
immed: boolean;
165
166
/**
167
* Warns about switch statements without default case
168
*/
169
leanswitch: boolean;
170
171
/**
172
* Requires constructor names to be capitalized
173
*/
174
newcap: boolean;
175
176
/**
177
* Prohibits use of arguments.caller and arguments.callee
178
*/
179
noarg: boolean;
180
181
/**
182
* Prohibits comma operator except in control statements
183
*/
184
nocomma: boolean;
185
186
/**
187
* Prohibits empty blocks
188
*/
189
noempty: boolean;
190
191
/**
192
* Warns about non-breaking space characters
193
*/
194
nonbsp: boolean;
195
196
/**
197
* Prohibits use of constructor functions for side effects
198
*/
199
nonew: boolean;
200
201
/**
202
* Prohibits return statements in async functions without await
203
*/
204
noreturnawait: boolean;
205
206
/**
207
* Enables warnings for regular expressions
208
*/
209
regexpu: boolean;
210
211
/**
212
* Prohibits grouping operators when not necessary
213
*/
214
singleGroups: boolean;
215
216
/**
217
* Requires trailing commas in multiline literals
218
*/
219
trailingcomma: boolean;
220
221
/**
222
* Requires variables to be declared before use
223
*/
224
undef: boolean;
225
226
/**
227
* Prohibits var statement, requires let/const
228
*/
229
varstmt: boolean;
230
231
/**
232
* Enables all enforcing options at once
233
*/
234
enforceall: boolean;
235
}
236
```
237
238
**Usage Examples:**
239
240
```javascript
241
// Basic enforcing options
242
const strictOptions = {
243
curly: true, // require braces
244
eqeqeq: true, // require ===
245
undef: true, // require variable declarations
246
unused: true // warn about unused variables
247
};
248
249
// ES6+ enforcing
250
const modernOptions = {
251
esversion: 6, // ES6 syntax support
252
varstmt: false, // allow var statements
253
futurehostile: true // warn about future reserved words
254
};
255
```
256
257
### Relaxing Options
258
259
More permissive options that disable specific warnings and allow certain patterns.
260
261
```javascript { .api }
262
interface RelaxingOptions {
263
/**
264
* Allows automatic semicolon insertion
265
*/
266
asi: boolean;
267
268
/**
269
* Allows assignments in conditions (if (a = b))
270
*/
271
boss: boolean;
272
273
/**
274
* Allows debugger statements
275
*/
276
debug: boolean;
277
278
/**
279
* Allows == null comparisons
280
*/
281
eqnull: boolean;
282
283
/**
284
* Allows elision in arrays ([1, , 3])
285
*/
286
elision: boolean;
287
288
/**
289
* Allows ES.next syntax (deprecated, use esversion)
290
*/
291
esnext: boolean;
292
293
/**
294
* Allows eval usage
295
*/
296
evil: boolean;
297
298
/**
299
* Allows expressions as statements
300
*/
301
expr: boolean;
302
303
/**
304
* Allows variables from outer scope to be redeclared
305
*/
306
funcscope: boolean;
307
308
/**
309
* Allows global strict mode
310
*/
311
globalstrict: boolean;
312
313
/**
314
* Allows __iterator__ property
315
*/
316
iterator: boolean;
317
318
/**
319
* Allows semicolon omission for last statement
320
*/
321
lastsemic: boolean;
322
323
/**
324
* Allows line breaks before operators
325
*/
326
laxbreak: boolean;
327
328
/**
329
* Allows comma-first style
330
*/
331
laxcomma: boolean;
332
333
/**
334
* Allows function definitions inside loops
335
*/
336
loopfunc: boolean;
337
338
/**
339
* Allows multiline strings with backslash
340
*/
341
multistr: boolean;
342
343
/**
344
* Allows Mozilla-specific syntax
345
*/
346
moz: boolean;
347
348
/**
349
* Allows missing typeof in comparisons
350
*/
351
notypeof: boolean;
352
353
/**
354
* Allows generators without yield
355
*/
356
noyield: boolean;
357
358
/**
359
* Allows ++ and -- operators
360
*/
361
plusplus: boolean;
362
363
/**
364
* Allows __proto__ property
365
*/
366
proto: boolean;
367
368
/**
369
* Allows javascript: URLs
370
*/
371
scripturl: boolean;
372
373
/**
374
* Allows [] notation when dot notation would work
375
*/
376
sub: boolean;
377
378
/**
379
* Allows weird constructor invocations
380
*/
381
supernew: boolean;
382
383
/**
384
* Allows this usage in non-constructor functions
385
*/
386
validthis: boolean;
387
388
/**
389
* Allows with statements
390
*/
391
withstmt: boolean;
392
}
393
```
394
395
**Usage Examples:**
396
397
```javascript
398
// Legacy code support
399
const legacyOptions = {
400
asi: true, // allow missing semicolons
401
boss: true, // allow assignments in conditions
402
expr: true, // allow expression statements
403
loopfunc: true // allow functions in loops
404
};
405
406
// Modern relaxed settings
407
const relaxedModern = {
408
esversion: 8,
409
esnext: false, // use specific esversion instead
410
validthis: true, // allow this in arrow functions context
411
laxcomma: true // allow comma-first style
412
};
413
```
414
415
### Environment Options
416
417
Environment-specific global variable definitions for different JavaScript runtime environments.
418
419
```javascript { .api }
420
interface EnvironmentOptions {
421
/**
422
* Browser environment globals (window, document, etc.)
423
*/
424
browser: boolean;
425
426
/**
427
* Node.js environment globals (global, process, Buffer, etc.)
428
*/
429
node: boolean;
430
431
/**
432
* Development/debugging globals (console, alert, etc.)
433
*/
434
devel: boolean;
435
436
/**
437
* jQuery library globals ($, jQuery)
438
*/
439
jquery: boolean;
440
441
/**
442
* MooTools library globals
443
*/
444
mootools: boolean;
445
446
/**
447
* Prototype.js library globals
448
*/
449
prototypejs: boolean;
450
451
/**
452
* Dojo Toolkit globals
453
*/
454
dojo: boolean;
455
456
/**
457
* YUI library globals
458
*/
459
yui: boolean;
460
461
/**
462
* Mocha testing framework globals (describe, it, etc.)
463
*/
464
mocha: boolean;
465
466
/**
467
* Jasmine testing framework globals
468
*/
469
jasmine: boolean;
470
471
/**
472
* QUnit testing framework globals
473
*/
474
qunit: boolean;
475
476
/**
477
* Web Worker environment globals
478
*/
479
worker: boolean;
480
481
/**
482
* Rhino JavaScript engine globals
483
*/
484
rhino: boolean;
485
486
/**
487
* Windows Script Host globals
488
*/
489
wsh: boolean;
490
491
/**
492
* PhantomJS globals
493
*/
494
phantom: boolean;
495
496
/**
497
* CouchDB globals
498
*/
499
couch: boolean;
500
501
/**
502
* ShellJS globals
503
*/
504
shelljs: boolean;
505
506
/**
507
* ES6 modules environment
508
*/
509
module: boolean;
510
511
/**
512
* Non-standard but widely supported globals
513
*/
514
nonstandard: boolean;
515
516
/**
517
* Typed array globals
518
*/
519
typed: boolean;
520
}
521
```
522
523
**Usage Examples:**
524
525
```javascript
526
// Browser + jQuery environment
527
const browserConfig = {
528
browser: true,
529
jquery: true,
530
devel: true // for console.log
531
};
532
533
// Node.js environment
534
const nodeConfig = {
535
node: true,
536
esversion: 8
537
};
538
539
// Testing environment
540
const testConfig = {
541
node: true,
542
mocha: true,
543
esversion: 6
544
};
545
```
546
547
### Value-Based Options
548
549
Options that accept specific values rather than just boolean true/false.
550
551
```javascript { .api }
552
interface ValueOptions {
553
/**
554
* ECMAScript version: 3, 5, 6, 7, 8, 9, 10, 11, etc.
555
*/
556
esversion: number;
557
558
/**
559
* Maximum line length
560
*/
561
maxlen: number;
562
563
/**
564
* Maximum number of errors before stopping
565
*/
566
maxerr: number;
567
568
/**
569
* Maximum nesting depth for blocks
570
*/
571
maxdepth: number;
572
573
/**
574
* Maximum number of statements per function
575
*/
576
maxstatements: number;
577
578
/**
579
* Maximum cyclomatic complexity
580
*/
581
maxcomplexity: number;
582
583
/**
584
* Maximum number of parameters per function
585
*/
586
maxparams: number;
587
588
/**
589
* Expected indentation (number of spaces or tabs)
590
*/
591
indent: number;
592
593
/**
594
* Quote style: true (consistent), 'single', 'double', false (any)
595
*/
596
quotmark: boolean | 'single' | 'double';
597
598
/**
599
* Variable shadowing: true (allow), false (prohibit), 'inner', 'outer'
600
*/
601
shadow: boolean | 'inner' | 'outer';
602
603
/**
604
* Strict mode: true (require), false (ignore), 'global', 'implied'
605
*/
606
strict: boolean | 'global' | 'implied';
607
608
/**
609
* Unused variables: true (warn), false (ignore), 'vars', 'strict'
610
*/
611
unused: boolean | 'vars' | 'strict';
612
613
/**
614
* Late definition: true (prohibit), false (allow), 'nofunc'
615
*/
616
latedef: boolean | 'nofunc';
617
618
/**
619
* Ignore specific warnings by code (e.g., 'W004,W008')
620
*/
621
ignore: string;
622
623
/**
624
* Custom ignore delimiters for inline ignoring
625
*/
626
ignoreDelimiters: string;
627
628
/**
629
* Predefined globals as array or object
630
*/
631
predef: string[] | {[key: string]: boolean};
632
633
/**
634
* Additional global variables
635
*/
636
globals: {[key: string]: boolean};
637
638
/**
639
* Scope identifier for internal use
640
*/
641
scope: string;
642
}
643
```
644
645
**Usage Examples:**
646
647
```javascript
648
// Comprehensive configuration
649
const fullConfig = {
650
// ECMAScript version
651
esversion: 8,
652
653
// Code quality limits
654
maxlen: 120,
655
maxdepth: 4,
656
maxstatements: 25,
657
maxcomplexity: 10,
658
maxparams: 5,
659
660
// Code style
661
indent: 2,
662
quotmark: 'single',
663
664
// Variable handling
665
unused: 'vars',
666
latedef: 'nofunc',
667
shadow: 'outer',
668
669
// Strict mode
670
strict: 'global',
671
672
// Custom globals
673
predef: ['myGlobal', 'anotherGlobal'],
674
675
// Environment
676
node: true,
677
678
// Ignore specific warnings
679
ignore: 'W004,W008'
680
};
681
```
682
683
### Configuration Hierarchy
684
685
JSHint follows a specific order when loading configuration:
686
687
1. Command line options (`--config`)
688
2. `.jshintrc` files (current directory walking up)
689
3. `package.json` `jshintConfig` property
690
4. `~/.jshintrc` (user home directory)
691
5. Default options
692
693
### Common Configuration Patterns
694
695
```javascript
696
// Strict modern JavaScript
697
const strict = {
698
esversion: 8,
699
strict: 'global',
700
undef: true,
701
unused: true,
702
curly: true,
703
eqeqeq: true,
704
freeze: true,
705
futurehostile: true
706
};
707
708
// Legacy browser code
709
const legacy = {
710
browser: true,
711
devel: true,
712
jquery: true,
713
asi: true,
714
boss: true,
715
expr: true,
716
loopfunc: true
717
};
718
719
// Node.js server code
720
const server = {
721
node: true,
722
esversion: 8,
723
strict: 'global',
724
undef: true,
725
unused: 'vars'
726
};
727
728
// Test files
729
const testing = {
730
node: true,
731
mocha: true,
732
esversion: 6,
733
expr: true, // allow expect().to.be.ok
734
unused: false // test helpers might not be used
735
};
736
```