Anton Kovalyov

JSHint Edition Update

01 Mar 2011 — San Francisco

Today we released 2011-03-01 edition of JSHint, a community-driven code quality tool. This is the first release since the announcement and so far the community feedback has been nothing but helpful.

I would like to personally thank the following contributors for providing patches that were included in this edition: sconover, schuyler1d and mbulman. I would also like to thank all the people who contributed by telling us what needs to be changed. Not all requests were included in this release but we’re making good progress so stay tuned for future releases.

Changelog

Three new options were added:

  1. jquery: Assume jQuery globals.
  2. couch: Assume CouchDB globals.
  3. asi: Tolerate the use of automatic semicolon insertion. ASI is one of the most controversial synctatic features and it is somewhat scary until you actually understand it. To use it or not is a matter of personal preference. Here is a good article that will help you to make an informed decision: JavaScript Semicolon Insertion.

New globals were added to the browser option: localStorage, applicationCache, openDatabase, Worker, WebSocket and FileReader.

In the boss mode (boss:true), JSHint will not complain about the == null relation. As the name suggests, use that mode only if you know what you’re doing. Here is a nice article about coercion rules in JavaScript: Truth, Equality and JavaScript.

JSHint behavior towards operators typeof and delete was changed. As GarretS noted in the ticket, those operators accept a reference. If, during evaluation, the base object of that reference is null, the result is not a runtime error.

Added support for the pattern of using undefined as a formal parameter. This is a pretty popular pattern used by libraries like jQuery.

(function (window, document, undefined) {
    // undefined will be undefined here even if there is
    //   var undefined = 'hello';
    // somewhere in the global scope
}(this, this.document));

JSHint now recognizes new Array(<expr>) as a valid expression. Expression new Array(); will still generate a warning because you should really use [] instead.

Added support for providing options to JSHint as command line arguments when used with our Rhino wrapper.

Added support for the explicit case statement fallthroughs. More often than not such fallthrough is unintentional and may lead to difficult bugs. And that’s why JSHint complains about it. But when you explicitly want to use that, you can keep JSHint happy by using special comments.

// JSHint will complain about this code:
switch (foo) {
case 1:
    doSomethingFirst();
case 2:
    doSomething();
}

// But it won't complain about this code because we explicitly stated our intention:
switch (foo) {
case 1:
    doSomethingFirst();
    /* falls through */
case 2:
    doSomething();
}

Added third formal parameter to the JSHINT function that allows you to provide a hash of pre-defined globals without using /*global ... */ comments.

JSHINT(code, options, { myGlobal: false, anotherGlobal: false /*, ... */ });

Brent Lintner created and maintains an official CLI and NPM package for JSHint: node-jshint. If you have NPM installed, just run npm install jshint. After the package is installed, you will be able to use jshint from your command line:

$ jshint ~/code/jshint/jshint.js
Lint Free!

Plugins

People wrote plugins for their favorite text editors and that is awesome.

If you wrote a plugin, let me know and I will update this post. We will also have that information on JSHint’s home page soon.

Roadmap

We will continue working on your requests. If you want something to be implemented sooner, vote the appropriate ticket up or consider sending a patch.

We also plan to make some cool changes to the website so that developers could read more information about each option and make an informed decision on whether they want to use it or not.

And that’s it for this release. Thanks again for all your support!