Skip to content

Latest commit

聽

History

History
83 lines (54 loc) 路 2.46 KB

indent.md

File metadata and controls

83 lines (54 loc) 路 2.46 KB

indent

馃摑 Enforce consistent indentation in JSON and CSS.

馃毇 Disabled by default.

馃敡 This rule is automatically fixable by the --fix CLI option.

Enforce leading indentation in JSON, JSONC, and JSON5 (@eslint/json) and CSS (@eslint/css). JSON checks nesting depth; CSS checks indentation style only.

JavaScript and TypeScript are excluded because their statements and expressions need more detailed indentation rules. Use @stylistic/indent for those languages.

Options

indent

Type: 'tab' | integer
Default: 'tab'

Use tabs, or a positive integer to set the number of spaces per indentation unit. Mixed tabs and spaces are rejected.

{
	'unicorn/indent': [
		'error',
		{
			indent: 2,
		},
	],
}

tabWidth

Type: integer
Default: 4

A positive integer tab stop width for CSS conversion, whether converting to tabs or spaces. Ignored for JSON.

Examples

JSON

Each open object or array adds one level. A line starting with } or ] uses one level less; only the first closing delimiter determines that line's indentation. Top-level content is unindented.

For {indent: 2}:

{
  "items": [
    true
  ]
}

Strings and comments do not affect depth. JSON5 indentation whitespace, including non-breaking spaces, is replaced.

CSS

Accepts any number of tabs in tab mode, or multiples of indent spaces in space mode. Nesting depth is not checked, so unindented lines are valid anywhere.

For {indent: 2}, both examples pass:

a {
  color: red;
}

b {
color: blue;
}

Fixes expand tabs using tab stops, then round width up to a whole indentation unit. With defaults, four spaces become one tab, five become two tabs, and a space followed by a tab becomes one tab. With {indent: 2, tabWidth: 4}, a tab followed by a space becomes six spaces.

Only ASCII spaces and tabs are treated as indentation. Unicode identifier characters, including non-breaking spaces, are preserved.

Preserved content

Preserves inline spacing, trailing whitespace, line endings, and non-whitespace token contents. Ignores blank lines and continuation lines inside multiline tokens and comments. Indentation before comment openers is checked.