Skip to main content

indent

Enforce consistent indentation throughout your code.
Rule Type: Layout
Fixable: Yes (automatically fixable)
Deprecated: Consider using Prettier

Rule Details

This rule enforces a consistent indentation style. The default is 4 spaces.

Options

The first option is the indent size:
  • Number (e.g., 2, 4) - Number of spaces
  • "tab" - Use tab character

Examples

Incorrect (default 4 spaces)

Correct (default 4 spaces)

Advanced Options

The second parameter is an object with many options:

SwitchCase

Default: 0 Indent level for case clauses:

VariableDeclarator

Default: 1 Indent level for multi-line variable declarations:

MemberExpression

Default: 1 Indent level for multi-line property chains:

FunctionDeclaration

Configure function declaration indentation:

CallExpression

Configure function call indentation:

ignoredNodes

Array of selectors to ignore:

Configuration Examples

Common Patterns

Switch Statements

Chained Methods

Multi-line Variables

When Not to Use It

Most modern projects use Prettier for formatting. If you use Prettier, disable this rule.
Disable if:
  • You use Prettier or another formatter
  • You don’t want to enforce indentation
  • Your team hasn’t agreed on indentation style