From 563a112354fb9029f38b8527c195fc32618e4773 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Mon, 14 Jul 2014 17:32:57 +0800 Subject: [PATCH] Jshint: document more enforcing options. --- jshint.md | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/jshint.md b/jshint.md index c6004c49a..3d5df5373 100644 --- a/jshint.md +++ b/jshint.md @@ -3,8 +3,9 @@ title: Jshint layout: default --- -### Relaxing +### [Relaxing](http://www.jshint.com/docs/options/#relaxing-options) +Enable these options to *not* throw errors in these conditions. /* jshint asi: true */ allow() @@ -35,14 +36,40 @@ layout: default } /* jshint sub: true */ - process.env['name_here']; + process.env['name_here'] -### Enforcement +### [Enforcing](http://www.jshint.com/docs/options/#enforcing-options) - /* jshint es3: true */ - // legacy IE compatibility - a.default = function() { ... }; - array = [ 1, 2, 3, ]; +Enable these options to catch more errors. + + /* jshint curly: true */ + while (day) // err: use { }'s + shuffle(); + + /* jshint eqeqeq: true */ + if (a == null) // err: use === + + /* jshint es3: true */ // ...for legacy IE compatibility + a.default = function() { ... }; // err: reserved word + array = [ 1, 2, 3, ]; // err: extra comma + + /* jshint forin: true */ + for (key in obj) { ... } // err: check obj.hasOwnProperty(key) + + /* jshint freeze: true */ + Array.prototype.count = ...; // err: don't modify native prototypes + + /* jshint indent: 4 */ + if (x) { // err: expected indent of 4, found 2 + ...; + } + + /* jshint quotmark: single */ + /* jshint quotmark: double */ + alert("hi"); // err: only single allowed + + /* jshint strict: true */ + function() { ... } // err: need "use strict" /* jshint white: true, indent: 4 */ /* jshint maxdepth: 2 */ @@ -56,13 +83,14 @@ layout: default /* jshint ignore:start */ /* jshint ignore:end */ -### Globals +### Globals and [Environments](http://www.jshint.com/docs/options/#environments) /* jshint undef: true */ /* global jQuery */ /* global -BAD_LIB */ - /* jshint browser: true */ window, document, ... + /* jshint devel: true */ console, alert, ... + /* jshint browser: true */ window, document, location, ... /* jshint node: true */ module, exports, console, process, ... /* jshint jquery: true */ jQuery, $