Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Last active January 23, 2023 10:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asharirfan/2bac7132e399f6531f9049b88100138d to your computer and use it in GitHub Desktop.
Save asharirfan/2bac7132e399f6531f9049b88100138d to your computer and use it in GitHub Desktop.
Introducing ESLint in your JS workflow

Introducing ESLint in Your JS Workflow

πŸ‘€ TL;DR

  1. ESLint is a modern linting tool for JS development to make your code consistent and bug free.
  2. Use npm install eslint --global to install ESLint globally.
  3. Go to your project in the terminal and run eslint --init to initiate and setup linting for your project.
  4. Install and automate your workflow in VSCode using ESLint extension.

πŸ“¦ Step 1: Installation

To install ESLint, you need Node β€” version greater or equal to 4.0 β€” and npm β€” version greater or equal to 2. Open the terminal and enter npm install eslint --global. This command will install ESLint globally in your computer.

alt text

🎯 Step 2: Setting Up ESLint

To use ESLint in your project, go to your project in the terminal and use eslint --init to initiate. Next, ESLint will ask you some questions to configure a basic setup for your project.

alt text

Answering these questions will create a configuration file β€” .eslintrc.json β€” for ESLint in your project folder.

alt text

πŸš€ Step 3: Automate Your Workflow

If you are using VSCode for coding, then you can automate your JS workflow with ESLint. Open VSCode, search for ESLint, and install the extension.

alt text

After installation, click on the Reload button to activate the extension. Now open the settings of VSCode and search for ESLint. Locate the setting eslint.autoFixOnSave, edit its value to true, and save the settings.

alt text

Yayy 🍺 That's it πŸ”₯ Now every time you save your JS file, your code will formatted automatically by ESLint πŸ’―

alt text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment