How to start with ESLint on VS Code

ESLint is a code testing tool that checks for syntax errors, and other potential errors and prevents any unused variables/functions that you forget to remove in your code. This article shows how to start using ESLint in your JavaScript project in VS Code.

Prerequisites

I am assuming you have VS Code installed on your machine. If you do not have it already, download and install it from the link here.

You also need Node.Js installed on your machine. If you do not have it already, download and install it from here.

Setup ESLint in VS Code

Open VS Code and go to the Extensions tab from the left sidebar. Search for ESLint.

Search for "ESLint" in VS Code Extensions Tab
Search for “ESLint” in VS Code Extensions Tab

Click “Install” at the right bottom of the ESLint search result. The plugin is installed in your VS Code. But that’s not all. You have to install it in your project (or global) as well in order to use it.

Install ESLint package

I recommend installing it globally so you can use it in other projects as well.

Use the command below to install ESLint globally.

ESLint global install
ESLint global install

Configure ESLint Init

Once you have installed ESLint on your machine, the next step is to configure/initialize ESLint in your project.

Go to your directory and open the command prompt.

Run eslint --init command and follow onscreen steps to complete it.

ESLint Init
ESLint Init

Follow the onscreen commands and choose the values as per your project. Once all the on-screen commands are done, it generates a .eslintrc.js file in your project root.

.eslintrc.js contents
.eslintrc.js contents

Start using ESLint

Now ESLint is successfully configured in the project. You can start writing ESLint compatible codes.

Here is a small demo of ESLint.

ESLint error enforcement
ESLint error enforcement

Conclusion

We learnt how to start using ESLint in a project and enforce the coding styles.

Let me know if you face any problems setting up ESLint.

Here are some other Node.Js recommended articles.

Leave a Reply

Your email address will not be published. Required fields are marked *