Code layout rules
no-adjacent-multiline-if
Section titled “no-adjacent-multiline-if”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.
What to do
Section titled “What to do”Start the next if on its own line. Add else only when the second condition must be mutually exclusive.
Example
Section titled “Example”Put a line break between } and the following independent if.
no-detached-call
Section titled “no-detached-call”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.
What to do
Section titled “What to do”Keep the opening call delimiter or template on the same line as its callee. Move intervening comments above the call.
Example
Section titled “Example”Use read(value) instead of placing (value) on a new line after read.
no-nested-template-literals
Section titled “no-nested-template-literals”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.
What to do
Section titled “What to do”Name the inner text before interpolating it, or place multiline templates on separate lines.
Example
Section titled “Example”const text = `outer ${`inner ${value}`}`; reports the inner template.
no-transposed-assignment
Section titled “no-transposed-assignment”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.
What to do
Section titled “What to do”Write the intended operator, or put a space after = and keep the unary operator beside its operand.
Example
Section titled “Example”count =+ increment; reports a finding. Use count += increment; when adding the increment.
no-unenclosed-multiline-block
Section titled “no-unenclosed-multiline-block”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.
What to do
Section titled “What to do”Add braces around every statement that belongs to the body, or move the next statement to its own line at the outer indent.
Example
Section titled “Example”if (isReady) start(); followed by an indented notify(); on the next line reports unenclosed at notify();.