jshint: update

This commit is contained in:
Rico Sta. Cruz 2017-09-12 20:37:40 +08:00
parent 6e6e264920
commit a8862a92b8
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 121 additions and 69 deletions

View File

@ -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}
```js
/* jshint asi: true */ /* jshint asi: true */
allow() allow()
missing_semicolons() missing_semicolons()
```
```js
/* jshint boss: true */ /* jshint boss: true */
if (m = str.match(/.../)) if (m = str.match(/.../))
```
```js
/* jshint debug: true */ /* jshint debug: true */
debugger; debugger;
```
```js
/* jshint eqnull: true */ /* jshint eqnull: true */
if (x == null) if (x == null)
```
```js
/* jshint evil: true */ /* jshint evil: true */
eval('...') eval('...')
```
```js
/* jshint expr: true */ /* jshint expr: true */
production && minify = true; production && minify = true;
div.innerWidth; div.innerWidth;
expect(x).be.true; expect(x).be.true;
```
```js
/* jshint laxcomma: true */ /* jshint laxcomma: true */
var one = 1 var one = 1
, two = 2; , two = 2;
```
```js
/* jshint loopfunc: true */ /* jshint loopfunc: true */
for (i=0; i<10; x++) { for (i=0; i<10; x++) {
(function(i) { ... })(i); (function(i) { ... })(i);
} }
```
```js
/* jshint sub: true */ /* jshint sub: true */
process.env['name_here'] process.env['name_here']
```
/* jshint globalstrict: true */ ```js
/* jshint strict: "global" */
"use strict"; "use strict";
```
### [Enforcing](http://www.jshint.com/docs/options/#enforcing-options) ### 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}
```js
/* jshint curly: true */ /* jshint curly: true */
while (day) // err: use { }'s while (day) // err: use { }'s
shuffle(); shuffle();
```
```js
/* jshint eqeqeq: true */ /* jshint eqeqeq: true */
if (a == null) // err: use === if (a == null) // err: use ===
```
/* jshint es3: true */ // ...for legacy IE compatibility ```js
/* jshint es3: true */
// ...for legacy IE compatibility
a.default = function() { ... }; // err: reserved word a.default = function() { ... }; // err: reserved word
array = [ 1, 2, 3, ]; // err: extra comma array = [ 1, 2, 3, ]; // err: extra comma
```
```js
/* jshint forin: true */ /* jshint forin: true */
for (key in obj) { ... } // err: check obj.hasOwnProperty(key) for (key in obj) { ... } // err: check obj.hasOwnProperty(key)
```
```js
/* jshint freeze: true */ /* jshint freeze: true */
Array.prototype.count = ...; // err: don't modify native prototypes Array.prototype.count = ...; // err: don't modify native prototypes
```
```js
/* jshint indent: 4 */ /* jshint indent: 4 */
if (x) { // err: expected indent of 4, found 2 if (x) { // err: expected indent of 4, found 2
...; ...;
} }
```
```js
/* jshint quotmark: single */ /* jshint quotmark: single */
/* jshint quotmark: double */ /* jshint quotmark: double */
alert("hi"); // err: only single allowed alert("hi"); // err: only single allowed
```
```js
/* jshint strict: true */ /* jshint strict: true */
function() { ... } // err: need "use strict" function() { ... } // err: need "use strict"
```
```js
/* jshint white: true, indent: 4 */ /* jshint white: true, indent: 4 */
/* jshint maxdepth: 2 */ /* jshint maxdepth: 2 */
/* jshint maxparams: 3 */ /* jshint maxparams: 3 */
/* jshint maxstatements: 4 */ /* jshint maxstatements: 4 */
/* jshint maxcomplexity: 5 */ /* jshint maxcomplexity: 5 */
/* jshint maxlen: 80 */ /* jshint maxlen: 80 */
```
### Ignore ### Ignore
```js
/* jshint ignore:start */ /* jshint ignore:start */
/* jshint ignore:end */ /* jshint ignore:end */
```
### Globals and [Environments](http://www.jshint.com/docs/options/#environments) ### Globals and Environments
```js
/* jshint undef: true */ /* jshint undef: true */
/* global jQuery */ /* global jQuery */
/* global -BAD_LIB */ /* global -BAD_LIB */
```
```js
/* jshint devel: true */ console, alert, ... /* jshint devel: true */ console, alert, ...
/* jshint browser: true */ window, document, location, ... /* jshint browser: true */ window, document, location, ...
/* jshint node: true */ module, exports, console, process, ... /* jshint node: true */ module, exports, console, process, ...
/* jshint jquery: true */ jQuery, $ /* 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>