I prefer JSHint over JSLint

When it comes to linting in JavaScript, there exist two mainstream solutions.

  1. JSLint written by Douglas Crockford.
  2. JSHint a fork of JSLint by the JavaScript community that is more flexible.

I have worked with JSlint for some time now. I grew frustrated with it because it is to rigid in the way it checks and enforces errors. There are numerous discussion happening on the Internet about what is right JavaScript and what is wrong JavaScript. Frankly though, I believe that when it comes down to introducing changes to a JavaScript file, you should only care for:

  • Adding/updating code so that it does not raise errors in the browser.

For example, a stray { bracket left in the code by an unfortunate typo, a forgotten global variable that really should be contained within the scope of a function, etc.

  • Writing code that will not be misinterpreted by less experienced developers.

JavaScript is a very flexible language. Before the introduction of the 'use strict'; feature in ECMAScript 5’s strict mode, the web was a wild jungle. Developers could write crazy code that worked, but was very hard to maintain and to read.

  • Writing optimal code.

If a change in a JavaScript file does not introduce a new feature or some kind of performance improvement, then it is strictly a stylistic change. Such things are very personal and are project dependent. A linter should not really care about such things as style, indentations, etc. It is up to the developer to maintain a common approach to style within a single JavaScript source file.

Because of the above arguments, I have switched over to JSHint.

For using with Emacs you can get the excellent jshint-mode by Dale Harvey. I strongly suggest that you update the jslint.js file that comes with this mode to the latest version. The latest version can be found at the download and install section of the JSHint site.

Checkout my Emacs config file for reference, if in doubt of how to install jshint-mode.