Lint the Code

Get introduced to different types of lint tools and learn how to ensure secure, error-free code by linting code.

Introduction

The 'use strict'; directive certainly provides much-needed relief, but it would be nice to know about potential errors before running the code. This is where the lint tools come in. Some notable lint tools are:

  • JSLint
  • JSHint
  • ESLint

💡 These tools can be installed easily with an npm install command.

JSLint

JSLint is an aggressive tool and, in fact, maybe a bit overly so when verifying code for compliance to the code quality standards it sets.

As soon as you unleash it on a piece of code, it will probably hurt your feelings.

JSHint

JSHint is also an aggressive tool, but at least it will give you a hug at the end of the ordeal.

It’s gentler and the more easily customizable of the two.

ESLint

ESLint is also easy to customize. Furthermore, it supports the rules for ES6 modules.

Later, we’ll use ESLint on a piece of code.

Example of bad code

First, let’s create a sample script with some badly written code in it:

Get hands-on with 1200+ tech skills courses.