Skip to main content

Quick Start Guide

Get ESLint analyzing your JavaScript code in under 5 minutes. This guide will walk you through the essentials.

Prerequisites

Before you begin, ensure you have Node.js installed:
Required: Node.js ^20.19.0, ^22.13.0, or >=24 built with SSL support.Check your version: node --version

Installation & Setup

1

Initialize ESLint Configuration

Run the interactive configuration wizard to set up ESLint for your project:
npm init @eslint/config@latest
This command will:
  • Detect your project type (JavaScript, TypeScript, React, etc.)
  • Ask about your code style preferences
  • Install required dependencies
  • Create an eslint.config.js file
The wizard is smart enough to detect if you’re using React, Vue, or TypeScript and will configure ESLint accordingly.
2

Run Your First Lint

Lint a single file:
npx eslint yourfile.js
Or lint an entire directory:
npx eslint src/
$ npx eslint src/index.js
# No output means no problems found!
3

Fix Problems Automatically

Many ESLint errors can be fixed automatically. Run with the --fix flag:
npx eslint --fix yourfile.js
This will automatically fix:
  • Spacing and indentation issues
  • Missing semicolons
  • Quote style inconsistencies
  • And many other stylistic problems
The --fix flag modifies your files in place. Make sure your code is committed or backed up before running it.
4

Add Lint Script to package.json

Add ESLint to your npm scripts for easy access:
package.json
{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint --fix ."
  }
}
Now you can run:
npm run lint      # Check for problems
npm run lint:fix  # Fix problems automatically

Understanding the Config File

The configuration wizard creates an eslint.config.js file. Here’s what a basic config looks like:
eslint.config.js
import { defineConfig } from "eslint/config";

export default defineConfig([
  {
    files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
    rules: {
      "prefer-const": "warn",
      "no-constant-binary-expression": "error",
    },
  },
]);

Configuration Breakdown

Specifies which files ESLint should analyze. Supports glob patterns:
files: ["**/*.js", "**/*.cjs", "**/*.mjs"]
This matches all .js, .cjs, and .mjs files in any directory.
Configures individual rules with severity levels:
  • "off" or 0 - Disable the rule
  • "warn" or 1 - Show warning (exit code 0)
  • "error" or 2 - Show error (exit code 1)
rules: {
  "no-unused-vars": "error",
  "no-console": "warn",
  "quotes": ["error", "double"],
}
Import configurations from presets:
import js from "@eslint/js";

export default defineConfig([
  js.configs.recommended,  // Use recommended rules
  {
    // Your custom rules
  },
]);

Common Rules to Start With

Here are some essential rules from the ESLint source code:

no-unused-vars

Type: Problem
Recommended: ✓
Disallow unused variables to keep your code clean.
// ❌ Error
const x = 5; // 'x' is never used

// ✓ Correct
const x = 5;
console.log(x);

no-undef

Type: Problem
Recommended: ✓
Disallow undefined variables to catch typos early.
// ❌ Error
console.log(foo); // 'foo' is not defined

// ✓ Correct
const foo = 'bar';
console.log(foo);

prefer-const

Type: Suggestion
Fixable: ✓
Suggest using const for variables that are never reassigned.
// ⚠ Warning
let x = 5; // 'x' is never reassigned

// ✓ Correct
const x = 5;

no-debugger

Type: Problem
Recommended: ✓
Disallow debugger statements in production code.
// ❌ Error
debugger;

// ✓ Use proper debugging tools instead

CLI Options Quick Reference

Here are the most commonly used CLI options from ESLint’s source:
# Fix problems automatically
eslint --fix file.js

# Use a specific config file
eslint -c custom-config.js file.js

# Specify output format
eslint --format json file.js

# Set maximum warnings before error
eslint --max-warnings 10 .

# Lint with quiet mode (errors only)
eslint --quiet file.js

# Debug mode for troubleshooting
eslint --debug file.js
For a complete list of CLI options, run npx eslint --help or check the options.js source file.

What’s Next?

Deep Dive into Installation

Learn about advanced installation options, pnpm setup, and TypeScript configuration

Configuration Guide

Master ESLint’s powerful configuration system

Rules Reference

Browse all 200+ built-in rules with examples

Create Custom Rules

Build your own rules to enforce project-specific patterns

Troubleshooting

Make sure your config file is named eslint.config.js, eslint.config.mjs, or eslint.config.cjs and is in your project root.You can also specify a config file explicitly:
npx eslint -c path/to/config.js file.js
This usually means ESLint can’t parse your JavaScript syntax. If you’re using modern syntax or TypeScript:
npm install --save-dev @typescript-eslint/parser
Then update your config:
import tsParser from "@typescript-eslint/parser";

export default defineConfig([
  {
    languageOptions: {
      parser: tsParser,
    },
  },
]);
Check that:
  1. The files pattern matches your source files
  2. The rule is spelled correctly (e.g., no-unused-vars, not no-unused-variables)
  3. Your config file is being loaded (run with --debug flag)
npx eslint --debug file.js

Need Help?