Skip to content

Code layout rules

Reports a multiline if statement whose closing line also starts the next independent if.

On in the all config.

Two adjacent conditions can look like an if/else chain when the second starts beside the first closing brace.

Start the next if on its own line. Add else only when the second condition must be mutually exclusive.

Put a line break between } and the following independent if.

Reports a single-argument call delimiter or tagged template detached from its callee by a line break.

On in the recommended and all configs.

A detached call or template can look like a separate statement even though it still invokes the preceding value.

Keep the opening call delimiter or template on the same line as its callee. Move intervening comments above the call.

Use read(value) instead of placing (value) on a new line after read.

Reports nested templates sharing the opening or closing line of their enclosing template.

On in the all config.

Several template delimiters on one line make interpolation boundaries difficult to follow.

Name the inner text before interpolating it, or place multiline templates on separate lines.

const text = `outer ${`inner ${value}`}`; reports the inner template.

Reports =+, =- and =! when spacing suggests the operator was transposed.

On in the recommended and all configs.

A unary operator after assignment can replace a value when the author intended an update or comparison.

Write the intended operator, or put a space after = and keep the unary operator beside its operand.

count =+ increment; reports a finding. Use count += increment; when adding the increment.

Reports a statement after an if, for, or while without braces whose layout makes it look like part of that body.

On in the recommended and all configs.

Without braces, only the first statement belongs to the body, so the next statement runs every time even though it looks conditional.

Add braces around every statement that belongs to the body, or move the next statement to its own line at the outer indent.

if (isReady) start(); followed by an indented notify(); on the next line reports unenclosed at notify();.