DEV Community

Lam
Lam

Posted on

Jshint Cheat Sheet

Also see

Globals and Environments

/* jshint undef: true */
/* global jQuery */
/* global -BAD_LIB */
Enter fullscreen mode Exit fullscreen mode
/* jshint devel: true */   console, alert, ...
/* jshint browser: true */ window, document, location, ...
/* jshint node: true */    module, exports, console, process, ...
/* jshint jquery: true */  jQuery, $
Enter fullscreen mode Exit fullscreen mode

See: Environments

Ignore

/* jshint ignore:start */
/* jshint ignore:end */
Enter fullscreen mode Exit fullscreen mode

Enforcing

Enable these options to catch more errors.
See: Enforcing
{: .-setup}

/* jshint curly: true */
while (day)                     // err: use { }'s
  shuffle();
Enter fullscreen mode Exit fullscreen mode
/* jshint eqeqeq: true */
if (a == null)                  // err: use ===
Enter fullscreen mode Exit fullscreen mode
/* jshint es3: true */
// ...for legacy IE compatibility
a.default = function() { ... }; // err: reserved word
array = [ 1, 2, 3, ];           // err: extra comma
Enter fullscreen mode Exit fullscreen mode
/* jshint forin: true */
for (key in obj) { ... }        // err: check obj.hasOwnProperty(key)
Enter fullscreen mode Exit fullscreen mode
/* jshint freeze: true */
Array.prototype.count = ...;    // err: don't modify native prototypes
Enter fullscreen mode Exit fullscreen mode
/* jshint indent: 4 */
if (x) {                        // err: expected indent of 4, found 2
  ...;
}
Enter fullscreen mode Exit fullscreen mode
/* jshint quotmark: single */
/* jshint quotmark: double */
alert("hi");                    // err: only single allowed
Enter fullscreen mode Exit fullscreen mode
/* jshint strict: true */
function() { ... }              // err: need "use strict"
Enter fullscreen mode Exit fullscreen mode
/* jshint white: true, indent: 4 */
/* jshint maxdepth: 2 */
/* jshint maxparams: 3 */
/* jshint maxstatements: 4 */
/* jshint maxcomplexity: 5 */
/* jshint maxlen: 80 */
Enter fullscreen mode Exit fullscreen mode

Relaxing

Enable these options to not throw errors in these conditions.
See: Relaxing
{: .-setup}

/* jshint asi: true */
allow()
missing_semicolons()
Enter fullscreen mode Exit fullscreen mode
/* jshint boss: true */
if (m = str.match(/.../))
Enter fullscreen mode Exit fullscreen mode
/* jshint debug: true */
debugger;
Enter fullscreen mode Exit fullscreen mode
/* jshint eqnull: true */
if (x == null)
Enter fullscreen mode Exit fullscreen mode
/* jshint evil: true */
eval('...')
Enter fullscreen mode Exit fullscreen mode
/* jshint expr: true */
production && minify = true;
div.innerWidth;
expect(x).be.true;
Enter fullscreen mode Exit fullscreen mode
/* jshint laxcomma: true */
var one = 1
  , two = 2;
Enter fullscreen mode Exit fullscreen mode
/* jshint loopfunc: true */
for (i=0; i<10; x++) {
  (function(i) { ... })(i);
}
Enter fullscreen mode Exit fullscreen mode
/* jshint sub: true */
process.env['name_here']
Enter fullscreen mode Exit fullscreen mode
/* jshint strict: "global" */
"use strict";
Enter fullscreen mode Exit fullscreen mode

Top comments (0)