2 title: no-unexpected-multiline
13 Semicolons are usually optional in JavaScript, because of automatic semicolon insertion (ASI). You can require or disallow semicolons with the [semi](./semi) rule.
15 The rules for ASI are relatively straightforward: As once described by Isaac Schlueter, a newline character always ends a statement, just like a semicolon, **except** where one of the following is true:
17 * 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 `.` or `,`.)
18 * The line is `--` or `++` (in which case it will decrement/increment the next token.)
19 * It is a `for()`, `while()`, `do`, `if()`, or `else`, and there is no `{`
20 * The next line starts with `[`, `(`, `+`, `*`, `/`, `-`, `,`, `.`, or some other binary operator that can only be found between two tokens in a single expression.
22 In the exceptions where a newline does **not** end a statement, a typing mistake to omit a semicolon causes two unrelated consecutive lines to be interpreted as one expression. Especially for a coding style without semicolons, readers might overlook the mistake. Although syntactically correct, the code might throw exceptions when it is executed.
26 This rule disallows confusing multiline expressions where a newline looks like it is ending a statement, but is not.
28 Examples of **incorrect** code for this rule:
33 /*eslint no-unexpected-multiline: "error"*/
39 [1, 2, 3].forEach(addNumber);
54 Examples of **correct** code for this rule:
59 /*eslint no-unexpected-multiline: "error"*/
68 [1, 2, 3].forEach(addNumber);
71 void [1, 2, 3].forEach(addNumber);
73 let x = function() {};
76 let tag = function() {}
84 You can turn this rule off if you are confident that you will not accidentally introduce code like this.
86 Note that the patterns considered problems are **not** flagged by the [semi](semi) rule.