Posted on: Written by: K-Sato
⚠️ This article was posted over 2 years ago. The information might be outdated. ⚠️

Table of Contents

Introduction

This is just a quick guideline to install ESLint in your JS applications.

Install packages

Follow the steps below and install all the necessary packages.

$ npm install --save-dev eslint
$ npm add --save-dev eslint-plugin-import eslint-plugin-jsx-a11y
$ npm install --save-dev prettier eslint-plugin-prettier
$ npm install --save-dev eslint-config-prettier
$ npm installl --save-dev eslint-plugin-react-hooks

Or just run

$ npm install --save-dev eslint eslint-plugin-import eslint-plugin-jsx-a11y  prettier eslint-plugin-prettier  eslint-config-prettier eslint-plugin-react-hooks

FYI, Difference between ESLint and Prettier.

Create your .eslintrc.json file

{
  "extends": [
    "react-app",
    "plugin:jsx-a11y/recommended",
    "prettier",
    "react-hooks"
  ],
  "plugins": ["jsx-a11y", "prettier"],
  "rules": {
    "prettier/prettier": "error"
  }
}

Add shortcut commands

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint . --ext .js,.jsx; exit 0",
    "lint-fix": "eslint --fix . --ext .js,.jsx; exit 0"
  }

How to use lint commands

Simply run the commands below to use ESLint.

// Run the command to check a specific file.
$ ./node_modules/.bin/eslint yourfile.js

// Run the command to fix errors.
// Each file
$ ./node_modules/.bin/eslint --fix yourfile.js
// Each Folder
$ ./node_modules/.bin/eslint --fix src/actions/

If you are also using Codeclimate

$ touch .codeclimate.yml
// .codeclimate.yml
eslint:
  enabled: true
  config:
    config: /vfhd-development-kit/projects/vf_helpdesk_frontend/.eslintrc.json

References

References

About the author

I am a web-developer based somewhere on earth. I primarily code in TypeScript, Go and Ruby at work. React, RoR and Gin are my go-to Frameworks.