UNPKG

6.39 kBMarkdownView Raw
1# at-rule-empty-line-before
2
3Require or disallow an empty line before at-rules.
4
5<!-- prettier-ignore -->
6```css
7a {}
8 /* ← */
9@media {} /* ↑ */
10/** ↑
11 * This line */
12```
13
14This rule ignores:
15
16- at-rules that are the very first node in the source
17- `@import` in Less.
18
19The [`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.
20
21## Options
22
23`string`: `"always"|"never"`
24
25### `"always"`
26
27There _must always_ be an empty line before at-rules.
28
29The following patterns are considered violations:
30
31<!-- prettier-ignore -->
32```css
33a {} @media {}
34```
35
36<!-- prettier-ignore -->
37```css
38a {}
39@media {}
40```
41
42The following patterns are _not_ considered violations:
43
44<!-- prettier-ignore -->
45```css
46a {}
47
48@media {}
49```
50
51### `"never"`
52
53There _must never_ be an empty line before at-rules.
54
55The following patterns are considered violations:
56
57<!-- prettier-ignore -->
58```css
59a {}
60
61@media {}
62```
63
64The following patterns are _not_ considered violations:
65
66<!-- prettier-ignore -->
67```css
68a {} @media {}
69```
70
71<!-- prettier-ignore -->
72```css
73a {}
74@media {}
75```
76
77## Optional secondary options
78
79### `except: ["after-same-name", "inside-block", "blockless-after-same-name-blockless", "blockless-after-blockless", "first-nested"]`
80
81#### `"after-same-name"`
82
83Reverse the primary option for at-rules that follow another at-rule with the same name.
84
85This means that you can group your at-rules by name.
86
87For example, with `"always"`:
88
89The following patterns are _not_ considered violations:
90
91<!-- prettier-ignore -->
92```css
93@charset "UTF-8";
94
95@import url(x.css);
96@import url(y.css);
97
98@media (min-width: 100px) {}
99@media (min-width: 200px) {}
100```
101
102<!-- prettier-ignore -->
103```css
104a {
105
106 @extends .foo;
107 @extends .bar;
108
109 @include x;
110 @include y {}
111}
112```
113
114#### `"inside-block"`
115
116Reverse the primary option for at-rules that are inside a block.
117
118For example, with `"always"`:
119
120The following patterns are considered violations:
121
122<!-- prettier-ignore -->
123```css
124a {
125
126 @extend foo;
127 color: pink;
128}
129
130b {
131 color: pink;
132
133 @extend foo;
134}
135```
136
137The following patterns are _not_ considered violations:
138
139<!-- prettier-ignore -->
140```css
141a {
142 @extend foo;
143 color: pink;
144}
145
146b {
147 color: pink;
148 @extend foo;
149}
150```
151
152#### `"blockless-after-same-name-blockless"`
153
154Reverse the primary option for blockless at-rules that follow another blockless at-rule with the same name.
155
156This means that you can group your blockless at-rules by name.
157
158Shared-line comments do not affect this option.
159
160For example, with `"always"`:
161
162The following patterns are _not_ considered violations:
163
164<!-- prettier-ignore -->
165```css
166@charset "UTF-8";
167
168@import url(x.css);
169@import url(y.css);
170```
171
172<!-- prettier-ignore -->
173```css
174@charset "UTF-8";
175
176@import url(x.css); /* comment */
177@import url(y.css);
178```
179
180<!-- prettier-ignore -->
181```css
182a {
183
184 @extends .foo;
185 @extends .bar;
186
187 @include loop;
188 @include doo;
189}
190```
191
192#### `"blockless-after-blockless"`
193
194Reverse the primary option for blockless at-rules that follow another blockless at-rule.
195
196Shared-line comments do not affect this option.
197
198For example, with `"always"`:
199
200The following patterns are considered violations:
201
202<!-- prettier-ignore -->
203```css
204@import url(x.css);
205
206@import url(y.css);
207
208@media print {}
209```
210
211The following patterns are _not_ considered violations:
212
213<!-- prettier-ignore -->
214```css
215@import url(x.css);
216@import url(y.css);
217
218@media print {}
219```
220
221<!-- prettier-ignore -->
222```css
223@import url(x.css); /* comment */
224@import url(y.css);
225
226@media print {}
227```
228
229#### `"first-nested"`
230
231Reverse the primary option for at-rules that are nested and the first child of their parent node.
232
233For example, with `"always"`:
234
235The following patterns are considered violations:
236
237<!-- prettier-ignore -->
238```css
239a {
240
241 @extend foo;
242 color: pink;
243}
244
245b {
246 color: pink;
247 @extend foo;
248}
249```
250
251The following patterns are _not_ considered violations:
252
253<!-- prettier-ignore -->
254```css
255a {
256 @extend foo;
257 color: pink;
258}
259
260b {
261 color: pink;
262
263 @extend foo;
264}
265```
266
267### `ignore: ["after-comment", "first-nested", "inside-block", "blockless-after-same-name-blockless", "blockless-after-blockless"]`
268
269#### `"after-comment"`
270
271Ignore at-rules that follow a comment.
272
273Shared-line comments do not trigger this option.
274
275The following patterns are _not_ considered violations:
276
277<!-- prettier-ignore -->
278```css
279/* comment */
280@media {}
281```
282
283<!-- prettier-ignore -->
284```css
285/* comment */
286
287@media {}
288```
289
290<!-- prettier-ignore -->
291```css
292@media {} /* comment */
293
294@media {}
295```
296
297#### `"first-nested"`
298
299Ignore at-rules that are nested and the first child of their parent node.
300
301For example, with `"always"`:
302
303The following patterns are _not_ considered violations:
304
305<!-- prettier-ignore -->
306```css
307@supports {
308 @media {}
309
310 @media {}
311}
312```
313
314#### `"inside-block"`
315
316Ignore at-rules that are inside a block.
317
318For example, with `"always"`:
319
320The following patterns are _not_ considered violations:
321
322<!-- prettier-ignore -->
323```css
324a {
325 @extend foo;
326 color: pink;
327}
328
329a {
330
331 @extend foo;
332 color: pink;
333}
334
335b {
336 color: pink;
337 @extend foo;
338}
339
340b {
341 color: pink;
342
343 @extend foo;
344}
345```
346
347#### `"blockless-after-same-name-blockless"`
348
349Ignore blockless at-rules that follow another blockless at-rule with the same name.
350
351This means that you can group your blockless at-rules by name.
352
353For example, with `"always"`:
354
355The following patterns are _not_ considered violations:
356
357<!-- prettier-ignore -->
358```css
359
360@charset "UTF-8";
361
362@import url(x.css);
363@import url(y.css);
364```
365
366<!-- prettier-ignore -->
367```css
368a {
369
370 @extends .foo;
371 @extends .bar;
372
373 @include loop;
374 @include doo;
375}
376```
377
378#### `"blockless-after-blockless"`
379
380Ignore blockless at-rules that follow another blockless at-rule.
381
382For example, with `"always"`:
383
384The following patterns are _not_ considered violations:
385
386<!-- prettier-ignore -->
387```css
388@import url(x.css);
389
390@import url(y.css);
391
392@media print {}
393```
394
395<!-- prettier-ignore -->
396```css
397@import url(x.css);
398@import url(y.css);
399
400@media print {}
401```
402
403### `ignoreAtRules: ["array", "of", "at-rules"]`
404
405Ignore specified at-rules.
406
407For example, with `"always"`.
408
409Given:
410
411```
412["import"]
413```
414
415The following patterns are _not_ considered violations:
416
417<!-- prettier-ignore -->
418```css
419@charset "UTF-8";
420@import {}
421```