Skip to main content

Rule Configuration

Rules are the core building block of ESLint. This page explains how to configure rule severity, options, and when rules are applied.

Rule Severity Levels

Each rule has a severity level that controls how ESLint enforces it:

Off

"off" or 0Rule is completely disabled

Warn

"warn" or 1Reports violations as warnings (doesn’t affect exit code)

Error

"error" or 2Reports violations as errors (exit code 1 when triggered)

Choosing Severity Levels

Use for Critical IssuesSet rules to "error" when:
  • Code would cause runtime errors
  • Violations break critical conventions
  • Used in CI/CD pipelines
  • Pre-commit hooks

Configuration Methods

Configuration Files

The primary way to configure rules is in your eslint.config.js file:
eslint.config.js
String format ("error", "warn", "off") is recommended for better readability.

Configuration Comments

You can also configure rules using inline comments:
Configuration comments have the highest priority and override all configuration file settings.

Rule Options

Many rules accept additional options to customize their behavior:

Basic Syntax

The first element in the array is always the severity level. All subsequent elements are options for the rule.

Object Options

Some rules accept object options:

Multiple Options

Rules can accept multiple option values:

Common Rule Examples

Examples:
Examples:
Examples:
Examples:
Options:
  • 2 or 4 - Number of spaces
  • "tab" - Use tabs

Inline Configuration Comments

Configure Rules Inline

Set rule configuration for a portion of a file:

With Descriptions

Add descriptions to explain why configuration is needed:
The description must:
  • Come after the configuration
  • Be separated by two or more consecutive - characters

Disabling Rules

Disable All Rules

Disable Specific Rules

Disable vs Turn Off

Temporary Disable
Use for temporarily disabling rules in specific code sections.
Use disable comments with caution:
  • Document the reason with a description
  • Prefer configuration files over inline comments
  • Create follow-up tasks for temporary disables
  • Review disable comments during code reviews

Rules from Plugins

When using plugin rules, prefix the rule ID with the plugin namespace:

In Configuration Comments

Plugins must be loaded in the configuration file before their rules can be used in comments.

Rule Cascading

When multiple configuration objects match a file, their rules are merged:

Partial Override

You can override just the severity while keeping options:

Disabling Inline Configuration

Prevent inline comments from modifying configuration:
With this setting, these comments are ignored:
  • /*eslint-disable*/
  • /*eslint-enable*/
  • /*global*/
  • /*eslint*/
  • // eslint-disable-line
  • // eslint-disable-next-line

Reporting Unused Directives

Unused Disable Directives

Report eslint-disable comments that don’t disable any violations:
Default: "warn" Options: "off", "warn", "error" (or 0, 1, 2)

Unused Inline Configs

Report inline config comments that match the current configuration:
Default: "off" Options: "off", "warn", "error" (or 0, 1, 2)

File-Specific Rules

Apply different rules to different file patterns:

Complete Example

eslint.config.js

Best Practices

Establish team conventions:
  • Error: Must fix (runtime issues, security, critical)
  • Warn: Should fix (code smells, best practices)
  • Off: Not applicable
Add comments explaining non-obvious choices:
Prefer configuration files over inline comments:
Regularly review and address:
  • Unused disable directives
  • Frequently disabled rules
  • Rules with many violations
  • Outdated rule configurations

Configuration

Learn about configuration files and objects

Core Concepts

Understanding rules, plugins, and more

Command Line

CLI options including —rule

Built-in Rules

Browse all available ESLint rules