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