2014-03-22 05:03:13 +01:00
|
|
|
---
|
|
|
|
title: Jshint
|
2015-11-24 06:09:17 +01:00
|
|
|
category: JavaScript libraries
|
2017-09-12 14:37:40 +02:00
|
|
|
updated: 2017-09-12
|
2014-03-22 05:03:13 +01:00
|
|
|
---
|
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
### Relaxing
|
2014-03-22 05:03:13 +01:00
|
|
|
|
2014-07-14 11:32:57 +02:00
|
|
|
Enable these options to *not* throw errors in these conditions.
|
2022-11-01 04:29:32 +01:00
|
|
|
See: [Relaxing](https://www.jshint.com/docs/options/#relaxing-options)
|
2017-09-12 14:37:40 +02:00
|
|
|
{: .-setup}
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint asi: true */
|
|
|
|
allow()
|
|
|
|
missing_semicolons()
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint boss: true */
|
|
|
|
if (m = str.match(/.../))
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint debug: true */
|
|
|
|
debugger;
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint eqnull: true */
|
|
|
|
if (x == null)
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint evil: true */
|
|
|
|
eval('...')
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint expr: true */
|
|
|
|
production && minify = true;
|
|
|
|
div.innerWidth;
|
|
|
|
expect(x).be.true;
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint laxcomma: true */
|
|
|
|
var one = 1
|
|
|
|
, two = 2;
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint loopfunc: true */
|
|
|
|
for (i=0; i<10; x++) {
|
|
|
|
(function(i) { ... })(i);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint sub: true */
|
|
|
|
process.env['name_here']
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint strict: "global" */
|
|
|
|
"use strict";
|
|
|
|
```
|
|
|
|
|
|
|
|
### Enforcing
|
2014-04-01 09:59:39 +02:00
|
|
|
|
2014-07-14 11:32:57 +02:00
|
|
|
Enable these options to catch more errors.
|
2022-11-01 04:29:32 +01:00
|
|
|
See: [Enforcing](https://www.jshint.com/docs/options/#enforcing-options)
|
2017-09-12 14:37:40 +02:00
|
|
|
{: .-setup}
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint curly: true */
|
|
|
|
while (day) // err: use { }'s
|
|
|
|
shuffle();
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint eqeqeq: true */
|
|
|
|
if (a == null) // err: use ===
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint es3: true */
|
|
|
|
// ...for legacy IE compatibility
|
|
|
|
a.default = function() { ... }; // err: reserved word
|
|
|
|
array = [ 1, 2, 3, ]; // err: extra comma
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint forin: true */
|
|
|
|
for (key in obj) { ... } // err: check obj.hasOwnProperty(key)
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint freeze: true */
|
|
|
|
Array.prototype.count = ...; // err: don't modify native prototypes
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint indent: 4 */
|
|
|
|
if (x) { // err: expected indent of 4, found 2
|
|
|
|
...;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint quotmark: single */
|
|
|
|
/* jshint quotmark: double */
|
|
|
|
alert("hi"); // err: only single allowed
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint strict: true */
|
|
|
|
function() { ... } // err: need "use strict"
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
/* jshint white: true, indent: 4 */
|
|
|
|
/* jshint maxdepth: 2 */
|
|
|
|
/* jshint maxparams: 3 */
|
|
|
|
/* jshint maxstatements: 4 */
|
|
|
|
/* jshint maxcomplexity: 5 */
|
|
|
|
/* jshint maxlen: 80 */
|
|
|
|
```
|
2014-06-21 15:31:47 +02:00
|
|
|
|
|
|
|
### Ignore
|
2014-04-01 09:59:39 +02:00
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
```js
|
|
|
|
/* jshint ignore:start */
|
|
|
|
/* jshint ignore:end */
|
|
|
|
```
|
2014-04-01 09:59:39 +02:00
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
### Globals and Environments
|
2014-07-14 05:23:52 +02:00
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
```js
|
|
|
|
/* jshint undef: true */
|
|
|
|
/* global jQuery */
|
|
|
|
/* global -BAD_LIB */
|
|
|
|
```
|
2014-03-22 05:03:13 +01:00
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
```js
|
|
|
|
/* jshint devel: true */ console, alert, ...
|
|
|
|
/* jshint browser: true */ window, document, location, ...
|
|
|
|
/* jshint node: true */ module, exports, console, process, ...
|
|
|
|
/* jshint jquery: true */ jQuery, $
|
|
|
|
```
|
2014-03-22 05:03:13 +01:00
|
|
|
|
2022-11-01 04:29:32 +01:00
|
|
|
See: [Environments](https://www.jshint.com/docs/options/#environments)
|
2014-04-01 09:59:39 +02:00
|
|
|
|
2017-09-12 14:37:40 +02:00
|
|
|
### Also see
|
2014-04-01 09:59:39 +02:00
|
|
|
|
2022-11-01 04:29:32 +01:00
|
|
|
* <https://www.jshint.com/docs/options/>
|
2017-09-12 14:37:40 +02:00
|
|
|
* <https://gist.github.com/haschek/2595796>
|