logoESLint React
Getting Started

JavaScript

Getting started using ESLint React in your JavaScript React project

This instruction requires the following minimum versions:

Installation

npm install --save-dev globals eslint @eslint/js @eslint-react/eslint-plugin

Configure ESLint

eslint.config.js
import globals from "globals";
import eslintJs from "@eslint/js";
import eslintReact from "@eslint-react/eslint-plugin";
import { defineConfig } from "eslint/config";
 
export default defineConfig([
  {
    files: ["**/*.js", "**/*.jsx"],
 
    // Extend recommended rule sets from:
    // 1. ESLint JS's recommended rules
    // 2. ESLint React's recommended rules
    extends: [
      eslintJs.configs.recommended,
      eslintReact.configs.recommended,
    ],
 
    // Configure language/parsing options
    languageOptions: {
      // Include browser global variables (window, document, etc.)
      globals: {
        ...globals.browser
      },
      parserOptions: {
        ecmaFeatures: {
          jsx: true, // Enable JSX syntax support
        },
      },
    },
 
    // Custom rule overrides (modify rule levels or disable rules)
    rules: {
      "@eslint-react/no-class-component": "error",
    },
  },
]);

Configure Language Service Integration (Optional)

eslint.config.js
// @ts-check
import tseslint from "typescript-eslint";
 
export default [
  {
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
];
jsconfig.json
{
  "compilerOptions": {
    // ...other options
    "jsx": "react-jsx",
  },
  "include": ["**/*.js", "**/*.jsx"]
}

TIP

Once you've correctly configured the language service integration for the files to be linted, ESLint React utilizes the information from the TypeScript compiler to provide better linting results.

For more information, see the Configure Language Config section.

On this page