Get Started with ESLint – A Complete Guide for Beginners

Get Started with ESLint – A Complete Guide for Beginners

ESLint Tutorial for Beginners: A Complete Guide for 2026

Writing JavaScript without a linter is like writing an essay without spell check. ESLint is the most widely used JavaScript linter. It reads your code, flags mistakes and style problems, and can fix many of them automatically. This beginner-friendly ESLint tutorial explains what ESLint is, how to set it up, how rules and plugins work, and how to use it in your editor.

What Is ESLint?

ESLint is an open-source tool that analyses JavaScript (and, with plugins, TypeScript, JSX and more) to find errors, risky patterns and style inconsistencies. This process is called linting. ESLint was created by Nicholas C. Zakas and first released in 2013, and it has since become a standard part of the JavaScript workflow.

Why ESLint Is Important

  • Catches bugs early: Finds problems such as unused variables or unreachable code before they reach production.
  • Enforces coding standards: Keeps a consistent style across a project and team.
  • Improves readability and maintenance: Cleaner code is easier to review and update.
  • Saves review time: Automates routine checks so reviewers can focus on logic.
  • Supports modern JavaScript: Works with current language features and popular frameworks through configuration and plugins.

How to Install ESLint

You need Node.js and npm installed. The recommended approach is to install ESLint in each project, not globally, so every project uses its own version.

The easiest way is the setup wizard, which installs ESLint and creates a configuration file for you:

npm init @eslint/config@latest

To install manually instead:

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

Yarn users can run yarn add --dev eslint @eslint/js globals.

How to Configure ESLint

Modern ESLint (version 9 and later) uses a flat config file named eslint.config.js. Older projects use .eslintrc files, which are now deprecated, so check which version your project uses.

Create eslint.config.js in your project root:

import js from "@eslint/js";
import globals from "globals";

export default [
  js.configs.recommended,
  {
    files: ["**/*.js"],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        ...globals.browser,
      },
    },
    rules: {
      "no-unused-vars": "warn",
      "no-console": "warn",
    },
  },
];

What this does:

  • js.configs.recommended turns on ESLint’s recommended rules.
  • languageOptions sets the JavaScript version, module type and global variables such as window and document.
  • rules lets you change individual rules. Each rule can be set to "off", "warn" or "error".

If your project uses an older ESLint version, the same ideas apply, but the file is .eslintrc.json and the format differs. See the ESLint migration guide for details.

How to Run ESLint

Lint a single file:

npx eslint your-file.js

Lint the whole project:

npx eslint .

Automatically fix problems that ESLint can fix safely:

npx eslint . --fix

Add shortcuts to the scripts section of your package.json:

"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
}

Now you can run npm run lint or npm run lint:fix.

Understanding ESLint Rules

Rules are the heart of ESLint. Each rule checks for one specific pattern. Common beginner-friendly rules include:

Rule

What it does

no-unused-vars

Flags variables that are declared but never used

no-console

Flags console.log and similar calls, often not wanted in production

no-duplicate-case

Prevents duplicate case labels in switch statements

no-empty-function

Disallows empty functions

eqeqeq

Requires === and !== instead of == and !=

no-undef

Flags use of variables that are not defined

You can browse the full list in the official rules reference at eslint.org.

Customising rules

Change a rule’s severity or options in the rules section of your config. To turn off a rule for a single line, use a comment:

// eslint-disable-next-line no-console
console.log("Debugging");

To turn off a rule for a whole file, add this at the top:

/* eslint-disable no-console */

Use these sparingly, and only when you have a good reason.

ESLint Plugins and Shareable Configs

Plugins add new rules or support for other tools. Shareable configs bundle a set of rules you can reuse.

Name

Purpose

eslint-plugin-react

Rules for React components and JSX

eslint-plugin-react-hooks

Rules for React Hooks

eslint-plugin-import

Rules for import and export statements

eslint-plugin-jest

Rules for Jest test files

typescript-eslint

Support and rules for TypeScript

eslint-config-airbnb

Shareable config based on Airbnb’s JavaScript style guide

eslint-config-prettier

Turns off ESLint rules that conflict with Prettier

Airbnb and Standard are shareable style configs, not plugins. Prettier is a code formatter, and you normally use it alongside ESLint rather than as an ESLint plugin.

ESLint vs Prettier

ESLint finds problems and enforces code-quality rules. Prettier focuses on formatting, such as indentation, quotes and line length. Many teams use both, with eslint-config-prettier to avoid conflicts.

ESLint vs JSHint

JSHint is an older linter with similar goals. ESLint is more configurable, supports custom rules and plugins, works with modern JavaScript, JSX and TypeScript, and has a larger community. This is why most modern projects use ESLint.

Using ESLint in Your Editor

Visual Studio Code

Install the official ESLint extension from the VS Code marketplace. It uses your project’s configuration file and underlines problems as you type. You can also configure it to fix issues on save.

WebStorm

WebStorm has built-in ESLint support. Enable it under the JavaScript code quality tools settings and point it to your project’s configuration.

Common ESLint Problems and How to Fix Them

Handling warnings and errors

Read each message and the rule name. Many problems can be fixed with --fix. For the rest, fix the code instead of disabling the rule when possible.

Configuration not working

  • Check that you are using the config file format that matches your ESLint version.
  • Make sure the files patterns in your config match the files you want to lint.
  • Use the ignores setting in flat config (or .eslintignore in older setups) to skip folders such as node_modules, dist or build.
  • Make sure plugins are installed and imported correctly.

Conflicts with Prettier

Install eslint-config-prettier and add it last in your config so formatting rules do not clash.

ESLint Best Practices

  • Start with the recommended rules and add more only when needed.
  • Install ESLint per project and commit your config file.
  • Run linting in CI so problems are caught before merging.
  • Run linting before commits, for example with a tool like Husky and lint-staged.
  • Use --fix regularly, then review the changes.
  • Document why you disable a rule when you do.

Career Benefits of Learning ESLint

Linting is a basic skill expected from JavaScript, React and Node.js developers. Knowing how to configure ESLint, share rules across a team and add linting to CI/CD pipelines helps you collaborate in professional and remote teams and shows attention to code quality.

Frequently Asked Questions (FAQs)

1. What is ESLint used for? ESLint analyses JavaScript code to find errors, risky patterns and style issues, and it can automatically fix many of them.

2. Is ESLint a formatter? Not mainly. ESLint is a linter focused on code quality, though it has some style rules. Prettier is better suited to formatting, and the two work well together.

3. Should I install ESLint globally or locally? Locally in each project is recommended, so every project uses the right version and the whole team shares the same setup.

4. What is the difference between .eslintrc and eslint.config.js? .eslintrc is the older configuration format. eslint.config.js is the newer flat config format, which is the default in ESLint v9 and later.

5. How do I customise ESLint rules? Edit the rules section of your config file, setting each rule to "off", "warn" or "error", or extend a shared config.

6. How do I disable an ESLint rule for one line or file? Use // eslint-disable-next-line rule-name for the next line, or /* eslint-disable rule-name */ at the top of a file.

7. Does ESLint work with React and TypeScript? Yes. Use eslint-plugin-react and eslint-plugin-react-hooks for React, and typescript-eslint for TypeScript.

8. How do I automatically fix ESLint errors? Run npx eslint . --fix. It fixes issues that are safe to change automatically, and you fix the rest by hand.

Conclusion

ESLint helps you write cleaner, safer and more consistent JavaScript. Install it in your project, start with the recommended rules, add plugins as your needs grow, and connect it to your editor and CI pipeline. Over time, it will save debugging time and improve the quality of your code.

Want to learn more about JavaScript and modern web development? Explore the courses at eLearning Solutions for expert guidance and hands-on training.

Call to action: Book a free demo class today and talk to our counsellors about the right course for you.

Name
admin
admin
https://www.thefullstack.co.in