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 disabledWarn
"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
- Error
- Warn
- Off
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 youreslint.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:Rule Options
Many rules accept additional options to customize their behavior:Basic Syntax
Object Options
Some rules accept object options:Multiple Options
Rules can accept multiple option values:Common Rule Examples
Semi (Semicolons)
Semi (Semicolons)
Quotes
Quotes
No Unused Vars
No Unused Vars
Prefer Const
Prefer Const
Max Length
Max Length
Indent
Indent
2or4- 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:- Come after the configuration
- Be separated by two or more consecutive
-characters
Disabling Rules
Disable All Rules
- Block
- Entire File
- Single Line
Disable Specific Rules
- Block
- Entire File
- Single Line
Disable vs Turn Off
- eslint-disable
- Rule: off
Temporary DisableUse for temporarily disabling rules in specific code sections.
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:/*eslint-disable*//*eslint-enable*//*global*//*eslint*/// eslint-disable-line// eslint-disable-next-line
Reporting Unused Directives
Unused Disable Directives
Reporteslint-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
Start with Recommended
Start with Recommended
Use recommended configs as a base:
Use Consistent Severity
Use Consistent Severity
Establish team conventions:
- Error: Must fix (runtime issues, security, critical)
- Warn: Should fix (code smells, best practices)
- Off: Not applicable
Document Rule Decisions
Document Rule Decisions
Add comments explaining non-obvious choices:
Minimize Inline Disables
Minimize Inline Disables
Prefer configuration files over inline comments:
Review Rule Violations
Review Rule Violations
Regularly review and address:
- Unused disable directives
- Frequently disabled rules
- Rules with many violations
- Outdated rule configurations
Related Resources
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