Course contentsShow
← JavaScript
Lesson 2557 of 2,72352. Linting and FormattingFree lesson

Understanding ESLint Rules

Learn how rules work, their severity levels (error, warn, off), and how to enable or disable specific rules.

Understanding ESLint Rules

You'll learn how ESLint rules control what's flagged as a problem, at what severity level, and how to configure them individually.

What Are ESLint Rules?

Rules are the core of ESLint—they're individual checks that examine your code for specific patterns or problems. Think of rules like individual inspectors at a checkpoint: one checks for semicolons, another looks for unused variables, another enforces consistent indentation. Each rule can be turned on, off, or set to different strictness levels.

Severity Levels: Error, Warn, Off

Every rule can be configured with one of three severity levels:

  • "off" (or 0): The rule is completely disabled. ESLint won't check for this issue at all.
  • "warn" (or 1): The rule flags violations as warnings. Your code still runs, but you'll see yellow/warning messages.
  • "error" (or 2): The rule flags violations as errors. ESLint will exit with a non-zero code, potentially blocking builds or commits.

Configuring Rules in .eslintrc

In your .eslintrc file, you set rules in the "rules" section:

{
  "rules": {
    "semi": "error",
    "no-unused-vars": "warn",
    "no-console": "off"
  }
}

This configuration requires semicolons (error), warns about unused variables, and ignores console statements entirely.

You can also use numeric values: "semi": 2 is identical to "semi": "error".

Rules with Options

Many rules accept additional configuration:

{
  "rules": {
    "quotes": ["error", "single"],
    "max-len": ["warn", { "code": 80 }]
  }
}

The first element is the severity level; remaining elements configure the rule's behavior.

Key Takeaway: ESLint rules are individually configurable checks with three severity levels (off/warn/error) that you control through the "rules" section of your configuration file.