jshint: update
This commit is contained in:
parent
6e6e264920
commit
a8862a92b8
190
jshint.md
190
jshint.md
|
@ -1,106 +1,158 @@
|
||||||
---
|
---
|
||||||
title: Jshint
|
title: Jshint
|
||||||
category: JavaScript libraries
|
category: JavaScript libraries
|
||||||
|
layout: 2017/sheet
|
||||||
|
updated: 2017-09-12
|
||||||
---
|
---
|
||||||
|
|
||||||
### [Relaxing](http://www.jshint.com/docs/options/#relaxing-options)
|
### Relaxing
|
||||||
|
|
||||||
Enable these options to *not* throw errors in these conditions.
|
Enable these options to *not* throw errors in these conditions.
|
||||||
|
See: [Relaxing](http://www.jshint.com/docs/options/#relaxing-options)
|
||||||
|
{: .-setup}
|
||||||
|
|
||||||
/* jshint asi: true */
|
```js
|
||||||
allow()
|
/* jshint asi: true */
|
||||||
missing_semicolons()
|
allow()
|
||||||
|
missing_semicolons()
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint boss: true */
|
```js
|
||||||
if (m = str.match(/.../))
|
/* jshint boss: true */
|
||||||
|
if (m = str.match(/.../))
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint debug: true */
|
```js
|
||||||
debugger;
|
/* jshint debug: true */
|
||||||
|
debugger;
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint eqnull: true */
|
```js
|
||||||
if (x == null)
|
/* jshint eqnull: true */
|
||||||
|
if (x == null)
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint evil: true */
|
```js
|
||||||
eval('...')
|
/* jshint evil: true */
|
||||||
|
eval('...')
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint expr: true */
|
```js
|
||||||
production && minify = true;
|
/* jshint expr: true */
|
||||||
div.innerWidth;
|
production && minify = true;
|
||||||
expect(x).be.true;
|
div.innerWidth;
|
||||||
|
expect(x).be.true;
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint laxcomma: true */
|
```js
|
||||||
var one = 1
|
/* jshint laxcomma: true */
|
||||||
, two = 2;
|
var one = 1
|
||||||
|
, two = 2;
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint loopfunc: true */
|
```js
|
||||||
for (i=0; i<10; x++) {
|
/* jshint loopfunc: true */
|
||||||
(function(i) { ... })(i);
|
for (i=0; i<10; x++) {
|
||||||
}
|
(function(i) { ... })(i);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint sub: true */
|
```js
|
||||||
process.env['name_here']
|
/* jshint sub: true */
|
||||||
|
process.env['name_here']
|
||||||
/* jshint globalstrict: true */
|
```
|
||||||
"use strict";
|
|
||||||
|
|
||||||
### [Enforcing](http://www.jshint.com/docs/options/#enforcing-options)
|
```js
|
||||||
|
/* jshint strict: "global" */
|
||||||
|
"use strict";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Enforcing
|
||||||
|
|
||||||
Enable these options to catch more errors.
|
Enable these options to catch more errors.
|
||||||
|
See: [Enforcing](http://www.jshint.com/docs/options/#enforcing-options)
|
||||||
|
{: .-setup}
|
||||||
|
|
||||||
/* jshint curly: true */
|
```js
|
||||||
while (day) // err: use { }'s
|
/* jshint curly: true */
|
||||||
shuffle();
|
while (day) // err: use { }'s
|
||||||
|
shuffle();
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint eqeqeq: true */
|
```js
|
||||||
if (a == null) // err: use ===
|
/* jshint eqeqeq: true */
|
||||||
|
if (a == null) // err: use ===
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint es3: true */ // ...for legacy IE compatibility
|
```js
|
||||||
a.default = function() { ... }; // err: reserved word
|
/* jshint es3: true */
|
||||||
array = [ 1, 2, 3, ]; // err: extra comma
|
// ...for legacy IE compatibility
|
||||||
|
a.default = function() { ... }; // err: reserved word
|
||||||
|
array = [ 1, 2, 3, ]; // err: extra comma
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint forin: true */
|
```js
|
||||||
for (key in obj) { ... } // err: check obj.hasOwnProperty(key)
|
/* jshint forin: true */
|
||||||
|
for (key in obj) { ... } // err: check obj.hasOwnProperty(key)
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint freeze: true */
|
```js
|
||||||
Array.prototype.count = ...; // err: don't modify native prototypes
|
/* jshint freeze: true */
|
||||||
|
Array.prototype.count = ...; // err: don't modify native prototypes
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint indent: 4 */
|
```js
|
||||||
if (x) { // err: expected indent of 4, found 2
|
/* jshint indent: 4 */
|
||||||
...;
|
if (x) { // err: expected indent of 4, found 2
|
||||||
}
|
...;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint quotmark: single */
|
```js
|
||||||
/* jshint quotmark: double */
|
/* jshint quotmark: single */
|
||||||
alert("hi"); // err: only single allowed
|
/* jshint quotmark: double */
|
||||||
|
alert("hi"); // err: only single allowed
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint strict: true */
|
```js
|
||||||
function() { ... } // err: need "use strict"
|
/* jshint strict: true */
|
||||||
|
function() { ... } // err: need "use strict"
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint white: true, indent: 4 */
|
```js
|
||||||
/* jshint maxdepth: 2 */
|
/* jshint white: true, indent: 4 */
|
||||||
/* jshint maxparams: 3 */
|
/* jshint maxdepth: 2 */
|
||||||
/* jshint maxstatements: 4 */
|
/* jshint maxparams: 3 */
|
||||||
/* jshint maxcomplexity: 5 */
|
/* jshint maxstatements: 4 */
|
||||||
/* jshint maxlen: 80 */
|
/* jshint maxcomplexity: 5 */
|
||||||
|
/* jshint maxlen: 80 */
|
||||||
|
```
|
||||||
|
|
||||||
### Ignore
|
### Ignore
|
||||||
|
|
||||||
/* jshint ignore:start */
|
```js
|
||||||
/* jshint ignore:end */
|
/* jshint ignore:start */
|
||||||
|
/* jshint ignore:end */
|
||||||
|
```
|
||||||
|
|
||||||
### Globals and [Environments](http://www.jshint.com/docs/options/#environments)
|
### Globals and Environments
|
||||||
|
|
||||||
/* jshint undef: true */
|
```js
|
||||||
/* global jQuery */
|
/* jshint undef: true */
|
||||||
/* global -BAD_LIB */
|
/* global jQuery */
|
||||||
|
/* global -BAD_LIB */
|
||||||
|
```
|
||||||
|
|
||||||
/* jshint devel: true */ console, alert, ...
|
```js
|
||||||
/* jshint browser: true */ window, document, location, ...
|
/* jshint devel: true */ console, alert, ...
|
||||||
/* jshint node: true */ module, exports, console, process, ...
|
/* jshint browser: true */ window, document, location, ...
|
||||||
/* jshint jquery: true */ jQuery, $
|
/* jshint node: true */ module, exports, console, process, ...
|
||||||
|
/* jshint jquery: true */ jQuery, $
|
||||||
|
```
|
||||||
|
|
||||||
|
See: [Environments](http://www.jshint.com/docs/options/#environments)
|
||||||
|
|
||||||
### Also see
|
### Also see
|
||||||
|
|
||||||
* http://www.jshint.com/docs/options/
|
* <http://www.jshint.com/docs/options/>
|
||||||
* https://gist.github.com/haschek/2595796
|
* <https://gist.github.com/haschek/2595796>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue