]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-multiple-empty-lines.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-multiple-empty-lines.md
1 ---
2 title: no-multiple-empty-lines
3 layout: doc
4 rule_type: layout
5 ---
6
7
8
9 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.
10
11 ## Rule Details
12
13 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.
14
15 ## Options
16
17 This rule has an object option:
18
19 * `"max"` (default: `2`) enforces a maximum number of consecutive empty lines.
20 * `"maxEOF"` enforces a maximum number of consecutive empty lines at the end of files.
21 * `"maxBOF"` enforces a maximum number of consecutive empty lines at the beginning of files.
22
23 ### max
24
25 Examples of **incorrect** code for this rule with the default `{ "max": 2 }` option:
26
27 ::: incorrect
28
29 ```js
30 /*eslint no-multiple-empty-lines: "error"*/
31
32 var foo = 5;
33
34
35 var bar = 3;
36 ```
37
38 :::
39
40 Examples of **correct** code for this rule with the default `{ "max": 2 }` option:
41
42 ::: correct
43
44 ```js
45 /*eslint no-multiple-empty-lines: "error"*/
46
47 var foo = 5;
48
49 var bar = 3;
50 ```
51
52 :::
53
54 ### maxEOF
55
56 Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 0 }` options:
57
58 ::: incorrect
59
60 ```js
61 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
62
63 var foo = 5;
64
65 var bar = 3;
66
67 ```
68
69 :::
70
71 Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 0 }` options:
72
73 ::: correct
74
75 ```js
76 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/
77
78 var foo = 5;
79
80 var bar = 3;
81 ```
82
83 :::
84
85 **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`.
86
87 **Incorrect**:
88
89 ```js
90 1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎
91 2 ⏎
92 3 var foo = 5;⏎
93 4 ⏎
94 5 ⏎
95 6 var bar = 3;⏎
96 7 ⏎
97 8
98 ```
99
100 **Correct**:
101
102 ```js
103 1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎
104 2 ⏎
105 3 var foo = 5;⏎
106 4 ⏎
107 5 ⏎
108 6 var bar = 3;⏎
109 7
110 ```
111
112 ### maxBOF
113
114 Examples of **incorrect** code for this rule with the `{ max: 2, maxBOF: 1 }` options:
115
116 ::: incorrect
117
118 ```js
119 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/
120
121 var foo = 5;
122
123 var bar = 3;
124 ```
125
126 :::
127
128 Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` options:
129
130 ::: correct
131
132 ```js
133 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/
134
135 var foo = 5;
136
137 var bar = 3;
138 ```
139
140 :::
141
142 ## When Not To Use It
143
144 If you do not care about extra blank lines, turn this off.