ESLint Installation and Setup

Installation Steps

  1. Install ESLint and React plugin:
    npm install --save-dev eslint eslint-plugin-react eslint-plugin-react-hooks

Configuration Steps

  1. Create .eslintrc.js or .eslintrc.json file in project root:
    • Location: .eslintrc.js or .eslintrc.json (root directory)
    {
      "extends": ["eslint:recommended", "plugin:react/recommended"],
      "parserOptions": {
        "ecmaVersion": 2022,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true
        }
      },
      "rules": {
        "react/react-in-jsx-scope": "off"
      }
    }
  2. Add to package.json scripts section:
    • Location: package.json (scripts section)
    "scripts": {
      "lint": "eslint .",
      "lint:fix": "eslint . --fix"
    }
  3. Verify configuration is committed to version control
    • Check: .eslintrc.js or .eslintrc.json should be in repository

Did you find this article useful?