Avoid unexpected multiline expressions (no-unexpected-multiline)
The rules for ASI are relatively straightforward: In short, as once described by Isaac Schlueter, a
\n character always ends a statement (just like a semicolon) unless one of the following is true:
- The statement has an unclosed paren, array literal, or object literal or ends in some other way that is not a valid way to end a statement. (For instance, ending with
- The line is
++(in which case it will decrement/increment the next token.)
- It is a
else, and there is no
- The next line starts with
., or some other binary operator that can only be found between two tokens in a single expression.
This particular rule aims to spot scenarios where a newline looks like it is ending a statement, but is not.
This rule is aimed at ensuring that two unrelated consecutive lines are not accidentially interpreted as a single expression.
The following patterns are considered warnings:
var foo = bar (1 || 2).baz(); var hello = 'world' [1, 2, 3].forEach(addNumber);
The following patterns are not considered warnings:
var foo = bar; (1 || 2).baz(); var foo = bar ;(1 || 2).baz() var hello = 'world'; [1, 2, 3].forEach(addNumber); var hello = 'world' void [1, 2, 3].forEach(addNumber);
When Not To Use It
You can turn this rule off if you are confident that you will not accidentally introduce code like this.
Note that the patterns considered warnings are not flagged by the semi rule.
This rule was introduced in ESLint 0.24.0.