UNPKG

4.66 kBMarkdownView Raw
1# rule-empty-line-before
2
3Require or disallow an empty line before rules.
4
5<!-- prettier-ignore -->
6```css
7a {}
8 /* ← */
9b {} /* ↑ */
10/** ↑
11 * This line */
12```
13
14This rule ignores rules that are the very first node in a source.
15
16The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule. We recommend to enable [`indentation`](../indentation/README.md) rule for better autofixing results with this rule.
17
18## Options
19
20`string`: `"always"|"never"|"always-multi-line"|"never-multi-line"`
21
22### `"always"`
23
24There _must always_ be an empty line before rules.
25
26The following patterns are considered problems:
27
28<!-- prettier-ignore -->
29```css
30a {} b {}
31```
32
33<!-- prettier-ignore -->
34```css
35a {}
36b {}
37```
38
39The following patterns are _not_ considered problems:
40
41<!-- prettier-ignore -->
42```css
43a {}
44
45b {}
46```
47
48### `"never"`
49
50There _must never_ be an empty line before rules.
51
52The following patterns are considered problems:
53
54<!-- prettier-ignore -->
55```css
56a {}
57
58b {}
59```
60
61The following patterns are _not_ considered problems:
62
63<!-- prettier-ignore -->
64```css
65a {} b {}
66```
67
68<!-- prettier-ignore -->
69```css
70a {}
71b {}
72```
73
74### `"always-multi-line"`
75
76There _must always_ be an empty line before multi-line rules.
77
78The following patterns are considered problems:
79
80<!-- prettier-ignore -->
81```css
82a {
83 color: red;
84}
85b {
86 color: blue;
87}
88```
89
90The following patterns are _not_ considered problems:
91
92<!-- prettier-ignore -->
93```css
94a {
95 color: red;
96}
97
98b {
99 color: blue;
100}
101```
102
103### `"never-multi-line"`
104
105There _must never_ be an empty line before multi-line rules.
106
107The following patterns are considered problems:
108
109<!-- prettier-ignore -->
110```css
111a {
112 color: red;
113}
114
115b {
116 color: blue;
117}
118```
119
120The following patterns are _not_ considered problems:
121
122<!-- prettier-ignore -->
123```css
124a {
125 color: red;
126}
127b {
128 color: blue;
129}
130```
131
132## Optional secondary options
133
134### `except: ["after-rule", "after-single-line-comment", "inside-block-and-after-rule", "inside-block", "first-nested"]`
135
136#### `"after-rule"`
137
138Reverse the primary option for rules that follow another rule.
139
140For example, with `"always"`:
141
142The following patterns are considered problems:
143
144<!-- prettier-ignore -->
145```css
146a {}
147
148b {}
149```
150
151The following patterns are _not_ considered problems:
152
153<!-- prettier-ignore -->
154```css
155a {}
156b {}
157```
158
159#### `"after-single-line-comment"`
160
161Reverse the primary option for rules that follow a single-line comment.
162
163For example, with `"always"`:
164
165The following patterns are considered problems:
166
167<!-- prettier-ignore -->
168```css
169/* comment */
170
171a {}
172```
173
174The following patterns are _not_ considered problems:
175
176<!-- prettier-ignore -->
177```css
178/* comment */
179a {}
180```
181
182#### `"inside-block-and-after-rule"`
183
184Reverse the primary option for rules that are inside a block and follow another rule.
185
186For example, with `"always"`:
187
188The following patterns are considered problems:
189
190<!-- prettier-ignore -->
191```css
192@media {
193
194 a {}
195
196 b {}
197}
198```
199
200The following patterns are _not_ considered problems:
201
202<!-- prettier-ignore -->
203```css
204@media {
205
206 a {}
207 b {}
208}
209```
210
211#### `"inside-block"`
212
213Reverse the primary option for rules that are inside a block.
214
215For example, with `"always"`:
216
217The following patterns are considered problems:
218
219<!-- prettier-ignore -->
220```css
221a {
222 color: red;
223
224 & b {
225 color: blue;
226 }
227}
228
229```
230
231The following patterns are _not_ considered problems:
232
233<!-- prettier-ignore -->
234```css
235a {
236 color: red;
237 & b {
238 color: blue;
239 }
240}
241```
242
243#### `"first-nested"`
244
245Reverse the primary option for rules that are nested and the first child of their parent node.
246
247For example, with `"always"`:
248
249The following patterns are considered problems:
250
251<!-- prettier-ignore -->
252```css
253@media {
254
255 a {}
256
257 b {}
258}
259```
260
261The following patterns are _not_ considered problems:
262
263<!-- prettier-ignore -->
264```css
265@media {
266 a {}
267
268 b {}
269}
270```
271
272### `ignore: ["after-comment", "first-nested", "inside-block"]`
273
274#### `"after-comment"`
275
276Ignore rules that follow a comment.
277
278For example, with `"always"`:
279
280The following patterns are _not_ considered problems:
281
282<!-- prettier-ignore -->
283```css
284/* comment */
285a {}
286```
287
288#### `"first-nested"`
289
290Ignore rules that are nested and the first child of their parent node.
291
292For example, with `"always"`:
293
294The following patterns are _not_ considered problems:
295
296<!-- prettier-ignore -->
297```css
298@media {
299 a {}
300
301 b {}
302}
303```
304
305#### `"inside-block"`
306
307Ignore rules that are inside a block.
308
309For example, with `"always"`:
310
311The following patterns are _not_ considered problems:
312
313<!-- prettier-ignore -->
314```css
315@media {
316 a {}
317}
318```
319
320<!-- prettier-ignore -->
321```css
322@media {
323 a {}
324 b {}
325}
326```