JSHint is a community-driven tool to detect errors and potential problems in JavaScript code and to enforce your team's coding conventions.
It is very flexible so you can easily adjust it to your particular coding guidelines and the environment you expect your code to execute in.
JSHint is a fork of JSLint, the tool written and maintained by Douglas Crockford.
The project originally started as an effort to make a more configurable version of JSLint—the one that doesn't enforce one particular coding style on its users—but then transformed into a separate static analysis tool with its own goals and ideals.
Our goal is to help JavaScript developers write complex programs without worrying about typos and language gotchas.
We believe that static code analysis programs—as well as other code quality tools—are important and beneficial to the JavaScript community and, thus, should not alienate their users.
Any code base eventually becomes huge at some point, and simple mistakes—that would not show themselves when written—can become show stoppers and waste hours of debugging. And this is when static code analysis tools come into play and help developers to spot such problems. JSHint scans a program written in JavaScript and reports about commonly made mistakes and potential bugs. The potential problem could be a syntax error, a bug due to implicit type conversion, a leaking variable or something else.
JSHint uses a Pratt parser implementation written by Douglas Crockford to scan your program.
Please note, that while static code analysis tools can spot many different kind of mistakes, it can't detect if your program is correct, fast or has memory leaks. You should always combine tools like JSHint with unit and functional tests as well as with code reviews.
JSHINT is a global function that takes three formal parameters:
var result = JSHINT(source, options, globals);
The first parameter is either a string or an array of strings. If it is a string,
it will be split on '\n' or '\r'. If it is an array of strings,
it is assumed that each string represents one line. The source can be JavaScript or
JSON.
If all of the enabled tests pass, JSHINT returns true. Otherwise, it
returns false.
If false, you can use JSHINT.errors to retrieve the errors or request a
complete data structure representing the "lint" by using JSHINT.data(). For
more information, read the JSHint source code (it's well documented).
You can also set options in-file globally or per-function:
/*jshint evil:true, boss:true */
function helloWorld() {
/*jshint expr:true */
}
In addition to options, you can let JSHint know what global variables it should expect:
/*global DISQUS:true, jQuery:false */
In the example above, JSHint will allow you to override DISQUS, but
complain if you try to override jQuery.
JSHint supports many different options that you can use to tune JSHint for your own, unique style of programming. If you are new to JavaScript or simply want a safer option just use the defaults. For any other case, we have a special page explaining all the options that we support.
Thanks to many contributors JSHint there are many plugins for all popular text editors and JavaScript platforms including NodeJS, Rhino and so on. Read more on our platforms page.
Current stable release (the one used on this site) is r03.