Linting with ESLint Manual

Projected Time

60 minutes

Prerequisites

Here are topics you must be comfortable with to get the maximum benefit out of this topic:

Motivation

Linting is a process of using a tool to automatically check your code for potential problems. There are several benefits for doing so for your code:

Objectives

Participants will be able to:

Specific Things To Learn

Materials

Lesson

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions like ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.

Let’s get started by installing ESLint in your project.

To install ESLint all you need to do is run the given command from the inside of your project folder. Installing ESLint globally is an option, but every project should have information about its dependencies to make sure that every developer working on the project is using the same tools.

$ npm install eslint --save-dev
$ npm install eslint -g

Once ESLint is installed in the project, we need to configure it according to our needs. This can be done in two ways:

$ npx eslint --init
$ eslint --init

refer Official Documentation for more provided in Supplement Materials

After configuring ESLint for the project, try to run ESLint on your project files by running the command:

$ eslint *.js

To avoid repeatedly typing this into the terminal, save it as an npm script. Open package.json and add another script "lint": "eslint *.js" to it.

"scripts": {
    "lint": "eslint *.js"
},

Now you are good to go with an npm script for linting:

$ npm run lint

Independent Practice

Integration

This can’t be any easier regardless of which Text-Editor/ IDE you are using. Installing a single plug-in is all you need to do. ESLint is so widely accepted that most of the popular Text-Editor and IDE offers a dedicated plugin for it.

Here are few links to follow:

For more information on integration refer the Integrations link provided in Supplemental Materials

Supplemental Materials