The rule indent
enforces the indentation style used in Origin₁ JavaScript and TypeScript files.
The indentation rules in order of lowest to highest priority are as follows:
- Lines between any of the bracket pairs
(…)
,[…]
,{…}
and<…>
are indented 4 spaces more than the line with the opening bracket. - Clauses of the statements
do…while
,for
,if
/else
,while
andwith
are indented 4 spaces more than the controlling statement, even when they are not enclosed in braces. - In the body of a switch statement,
case
anddefault
labels have the same indentation as the line with the opening brace. - In a multiline template, expressions are indented like regular code, but lines that start with string texts are ignored.
- Empty lines are ignored.
- In a multiline comment, each line is indented or unindented the same number of spaces as the first line.
This rule accepts a single option: an integer value which defines the expected indentation of the
first line of code, in units of 4 spaces (default 0
).
Negative values are allowed.
When a line is assigned an indentation of 0 or less spaces, it is expected to have no leading
spaces.
/* eslint @origin-1/indent: "error" */
const foo =
bar
(
baz
);
if (foo)
bar();
switch (foo) {
case 0:
bar(baz);
break;
default:
bar();
break;
}
const foobaz = `${
/* Your comment here. */
foo + baz
}`;
/* eslint @origin-1/indent: "error" */
const foo =
bar
(
baz
);
if (foo)
bar();
switch (foo) {
case 0:
bar(baz);
break;
default:
bar();
break;
}
const foobaz = `${
/* Your comment here. */
foo + baz
}`;
/* eslint @origin-1/indent: ["error", 2] */
if (foo)
bar();
/* eslint @origin-1/indent: ["error", 2] */
if (foo)
bar();
/* eslint @origin-1/indent: ["error", -1] */
(function () {
if (foo)
bar();
})();
/* eslint @origin-1/indent: ["error", -1] */
(function () {
if (foo)
bar();
})();