@@ -352,6 +352,75 @@ Example configuration:
352
352
}
353
353
```
354
354
355
+ ### [ no-unexpected-multiline]
356
+
357
+ ** This rule requires special attention when writing code.**
358
+
359
+ This rule disallows confusing multiline expressions where a newline looks like
360
+ it is ending a statement, but is not.
361
+
362
+ For example, the rule could warn about this:
363
+
364
+ ``` js
365
+ var hello = " world"
366
+ [1 , 2 , 3 ].forEach (addNumber)
367
+ ```
368
+
369
+ Prettier usually formats this in a way that makes it obvious that a semicolon
370
+ was missing:
371
+
372
+ ``` js
373
+ var hello = " world" [(1 , 2 , 3 )].forEach (addNumber);
374
+ ```
375
+
376
+ However, there are cases where Prettier breaks things into several lines such
377
+ that the ` no-unexpected-multiline ` conflicts.
378
+
379
+ ``` js
380
+ const value = text .trim ().split (" \n " )[position].toLowerCase ();
381
+ ```
382
+
383
+ Prettier breaks it up into several lines, though, causing a conflict:
384
+
385
+ ``` js
386
+ const value = text
387
+ .trim ()
388
+ .split (" \n " )
389
+ [position].toLowerCase ();
390
+ ```
391
+
392
+ If you like this rule, it can usually be used with Prettier without problems,
393
+ but occasionally you might need to either temporarily disable the rule or
394
+ refactor your code.
395
+
396
+ ``` js
397
+ const value = text
398
+ .trim ()
399
+ .split (" \n " )
400
+ // eslint-disable-next-line no-unexpected-multiline
401
+ [position].toLowerCase ();
402
+
403
+ // Or:
404
+
405
+ const lines = text .trim ().split (" \n " );
406
+ const value = lines[position].toLowerCase ();
407
+ ```
408
+
409
+ ** Note:** If you _ do_ enable this rule, you have to run ESLint and Prettier as
410
+ two separate steps (and ESLint first) in order to get any value out of it.
411
+ Otherwise Prettier might reformat your code in such a way that ESLint never gets
412
+ a chance to report anything (as seen in the first example).
413
+
414
+ Example configuration:
415
+
416
+ ``` json
417
+ {
418
+ "rules" : {
419
+ "no-unexpected-multiline" : " error"
420
+ }
421
+ }
422
+ ```
423
+
355
424
### [ quotes]
356
425
357
426
** This rule requires certain options.**
@@ -454,6 +523,7 @@ several other npm scripts:
454
523
[ no-confusing-arrow ] : https://eslint.org/docs/rules/no-confusing-arrow
455
524
[ no-mixed-operators ] : https://eslint.org/docs/rules/no-mixed-operators
456
525
[ no-tabs ] : https://eslint.org/docs/rules/no-tabs
526
+ [ no-unexpected-multiline ] : https://eslint.org/docs/rules/no-unexpected-multiline
457
527
[ quotes ] : https://eslint.org/docs/rules/quotes
458
528
[ travis-badge ] : https://travis-ci.org/prettier/eslint-config-prettier.svg?branch=master
459
529
[ travis ] : https://travis-ci.org/prettier/eslint-config-prettier
0 commit comments