DEV Community

Lam
Lam

Posted on

3 3

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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more