Linting

If lint (software) is software doing static code analysis on your code, linting must be the process of analyzing the code. As the article tells you, this is the part of testing your code which a computer can be programmed to do. For JavaScript we have an array of tools capable of doing just that. Here's a list.

JSLint, JavaScript Syntax Checker and Validator

The JSLint application was written by Douglas Crockford as code quality tool for JavaScript. In his book [Cro08] he writes a very brief style guide, chapter 9. The first subject he mentions is that he always uses blocks with structured statements such as if, and while. This means using braces, { … } to avoid maintenance errors. In appendix C of the book he writes:

JSLint defines a professional subset of JavaScript, a stricter language than that defined by the third edition of ECMAScript Language Specification. The subset is closely related to the style recommendations from Chapter 9.

The syntax rules that he recommends are implemented into an application, JSLint, freely available for your use at https://jslint.com/. Crockford is by many considered rather extreme, and by some to be obnoxiously opinionated. The application, however, gives you several configuration parameters, so that you can tailor it to suit your own style viewpoint.

Now we shall go to the application website, make some experiments, see what happens, and discuss the consequences.

Figure 29.1. JSLint
JSLint

JSHint, a Community Driven Variant of JSLint

Many were offended by the tone of JSLint. Some of them decided to take action and create their own linter. The result was/is https://jshint.com/. A capricious aside: One of the maintainers over the years of JSHint has been Douglas Crockford. They thank him, and others on their site.

The purpose is the same, better, cleaner, more maintainable code. Let us do some of the same experiments we tried with JSLint.

JSHint may be downloaded and used locally, either from a browser, or, as a Node.js application, as a command line tool. If you use it web based, it is always up to date.

Figure 29.2. JSHint
JSHint

ESLint, JavaScript Syntax Checker and Formatter

ESLint is an alternative to the above. It is popular with many developers, and we shall look at it. It has Node.js as a prerequisite, therefore we shall defer the intro to a later time. The software is also not web based. It must be installed on the developers computer. The website of the project is at https://eslint.org/.