]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-multiple-empty-lines.md
1a04841825c16b1b097b50b01414f80d06f6c8aa
[pve-eslint.git] / eslint / docs / rules / no-multiple-empty-lines.md
1 # disallow multiple empty lines (no-multiple-empty-lines)
2
3 Some developers prefer to have multiple blank lines removed, while others feel that it helps improve readability. Whitespace is useful for separating logical sections of code, but excess whitespace takes up more of the screen.
4
5 ## Rule Details
6
7 This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines has been exceeded.
8
9 ## Options
10
11 This rule has an object option:
12
13 - `"max"` (default: `2`) enforces a maximum number of consecutive empty lines.
14 - `"maxEOF"` enforces a maximum number of consecutive empty lines at the end of files.
15 - `"maxBOF"` enforces a maximum number of consecutive empty lines at the beginning of files.
16
17 ### max
18
19 Examples of **incorrect** code for this rule with the default `{ "max": 2 }` option:
20
21 ```js
22 /*eslint no-multiple-empty-lines: "error"*/
23
24 var foo = 5;
25
26
27
28 var bar = 3;
29 ```
30
31 Examples of **correct** code for this rule with the default `{ "max": 2 }` option:
32
33 ```js
34 /*eslint no-multiple-empty-lines: "error"*/
35
36 var foo = 5;
37
38
39 var bar = 3;
40 ```
41
42 ### maxEOF
43
44 Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 0 }` options:
45
46 ```js
47 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
48
49 var foo = 5;
50
51
52 var bar = 3;
53
54
55 ```
56
57 Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 0 }` options:
58
59 ```js
60 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
61
62 var foo = 5;
63
64
65 var bar = 3;
66 ```
67
68 **Note**: Although this ensures zero empty lines at the EOF, most editors will still show one empty line at the end if the file ends with a line break, as illustrated below. There is no empty line at the end of a file after the last `\n`, although editors may show an additional line. A true additional line would be represented by `\n\n`.
69
70 **Incorrect**:
71
72 ```js
73 1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎
74 2 ⏎
75 3 var foo = 5;⏎
76 4 ⏎
77 5 ⏎
78 6 var bar = 3;⏎
79 7 ⏎
80 8
81 ```
82
83 **Correct**:
84
85 ```js
86 1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎
87 2 ⏎
88 3 var foo = 5;⏎
89 4 ⏎
90 5 ⏎
91 6 var bar = 3;⏎
92 7
93 ```
94
95 ### maxBOF
96
97 Examples of **incorrect** code for this rule with the `{ max: 2, maxBOF: 1 }` options:
98
99 ```js
100 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/
101
102
103 var foo = 5;
104
105
106 var bar = 3;
107 ```
108
109 Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` options:
110
111 ```js
112 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/
113
114 var foo = 5;
115
116
117 var bar = 3;
118 ```
119
120 ## When Not To Use It
121
122 If you do not care about extra blank lines, turn this off.