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.
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.
npm install -g eslint
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.
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.
Start using ESLint
Now ESLint is successfully configured in the project. You can start writing ESLint compatible codes.
Conclusion
We learned 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.