Originally published at: http://www.sitepoint.com/comparison-javascript-linting-tools/
A linting tool helps me avoid silly mistakes when writing JavaScript. Despite my many years of experience, I still type variable names incorrectly, make syntax errors and forget to handle my errors properly. A good linting tool, or a linter, will tell me about this before I waste my time—or worse, my client’s time. A good linting tool can also help make sure a project adheres to a coding standard.
There are many linters available for JavaScript, but how do you choose which one to use? Let’s take a look at both the features and the pros and cons of four popular alternatives: JSLint, JSHint, JSCS and ESLint.
Overview
The four tools work in the same basic way. They have a set of rules which they use to analyze and report problems in JavaScript files. They can be installed via npm. They are used from the command line by passing in files, are available as plugins for tools like Grunt, or are integrated into editors. They all support using comments for configuration.
But that’s where the similarities end. Each tool has its own pros and cons—it’s just that some have more pros than others.
JSLint
JSLint is the oldest of the four. Douglas Crockford created it in 2002 to enforce what, in his experience, are the good parts of JavaScript. If you agree with the good parts, JSLint can be a good tool—you install it and it’s ready to go.
The downsides are that JSLint is not configurable or extensible. You can’t disable many features at all, and some of them lack documentation. The official website is not very helpful, for example it lacks any information on how to integrate it with your editor.
Pros
- Comes configured and ready to go (if you agree with the rules it enforces)
Cons
- JSLint doesn’t have a configuration file, which can be problematic if you need to change the settings
- Limited number of configuration options, many rules cannot be disabled
- You can’t add custom rules
- Undocumented features
- Difficult to know which rule is causing which error